2012-04-04 138 views
0
I have a class called A which has set of object of B. On inserting the A all the objects in the set must be inserted. But in my case only the object A is inserting not the sets. 

注意类B也有对象的集合,在某些情况下可能为空。 关系:1 ----> *类 Page.hbm.xml休眠插入一对多

<hibernate-mapping> 
     <class catalog="uml" name="com.project.lwuml.classdiagram.entity.Page" table="page"> 
     <id name="id" type="java.lang.Integer"> 
      <column name="id"/> 
      <generator class="identity"/> 
     </id> 
     <property name="content" type="string"> 
      <column length="65535" name="content"/> 
     </property> 
     <set inverse="true" name="classboxes" table="classbox" lazy="true" fetch="select"> 
      <key> 
      <column name="page_id" not-null="true"/> 
      </key> 
      <one-to-many class="com.project.lwuml.classdiagram.entity.Classbox"/> 
     </set> 
     </class> 
    </hibernate-mapping> 

Classboxes.hbm.xml

<hibernate-mapping> 
     <class catalog="uml" name="com.project.lwuml.classdiagram.entity.Classbox" table="classbox"> 
     <id name="id" type="java.lang.Integer"> 
      <column name="id"/> 
      <generator class="identity"/> 
     </id> 
     <many-to-one class="com.project.lwuml.classdiagram.entity.Accessspecifiers" fetch="select" name="accessspecifiers"> 
      <column name="accessspecifiers_id" not-null="true"/> 
     </many-to-one> 
     <many-to-one class="com.project.lwuml.classdiagram.entity.Page" fetch="select" name="page"> 
      <column name="page_id" not-null="true"/> 
     </many-to-one> 
     <property name="className" type="string"> 
      <column length="128" name="className"/> 
     </property> 
     <set inverse="true" lazy="true" name="classmethods"> 
      <key> 
      <column name="classbox_id" not-null="true"/> 
      </key> 
      <one-to-many class="com.project.lwuml.classdiagram.entity.Classmethod"/> 
     </set> 
     <set inverse="true" name="classdatamembers"> 
      <key> 
      <column name="classbox_id" not-null="true"/> 
      </key> 
      <one-to-many class="com.project.lwuml.classdiagram.entity.Classdatamember"/> 
     </set> 
     </class> 
    </hibernate-mapping> 

我使用Struts的春天冬眠。任何人都可以帮助我。 在此先感谢

+1

请留下XML和移动注解 – 2012-04-04 16:43:38

回答