随笔 - 6  文章 - 129  trackbacks - 0
<2014年6月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

常用链接

留言簿(14)

随笔档案(6)

文章分类(467)

文章档案(423)

相册

收藏夹(18)

JAVA

搜索

  •  

积分与排名

  • 积分 - 690045
  • 排名 - 60

最新评论

阅读排行榜

评论排行榜

映射文件
<hibernate-mapping>
    <class name="org.gecs.hibernate.test.AdDepartment" table="AD_DEPARTMENT" schema="BARCODE"
           dynamic-insert="true" dynamic-update="true">
        <id name="adDepartmentId" type="long">
            <column name="AD_DEPARTMENT_ID" precision="22" scale="0" />
            <generator class="sequence">
                <param name="sequence">AD_DEPARTMENT_SEQ</param>
            </generator>
        </id>
        <property name="departmentName" type="string">
            <column name="DEPARTMENT_NAME" length="50" not-null="true" />
        </property>
        <property name="active" type="java.lang.Character" insert="false" update="true">
            <column name="ACTIVE" length="1" />
        </property>
        <property name="createdTime" type="date" insert="false" update="false">
            <column name="CREATED_TIME" length="7" />
        </property>
        <property name="createdUser" type="string">
            <column name="CREATED_USER" length="20" not-null="true" />
        </property>
        
        <many-to-one name="parentDepartment" column="PARENT_DEPARTMENT_ID"/>
        
        <set name="childDepartment" cascade="save-update" lazy="true" inverse="true">
            <key column="PARENT_DEPARTMENT_ID"/>
            <one-to-many class="org.gecs.hibernate.test.AdDepartment"/>
        </set>

    </class>
</hibernate-mapping>

表结构:
测试代码:
public void testSave() {
        AdDepartment department = new AdDepartment();
        department.setDepartmentName("華南資訊處");
        department.setCreatedUser("bob");
        
        AdDepartment child_department = new AdDepartment();
        child_department.setDepartmentName("PCBA應用系統部");
        child_department.setCreatedUser("bob");
        child_department.setParentDepartment(department);
        //
        department.getChildDepartment().add(child_department);
        
        Transaction tran = session.beginTransaction();
        session.save(department);
        //session.save(child_department);
        tran.commit();
    }

效果:


posted on 2011-07-07 15:35 Ke 阅读(1031) 评论(1)  编辑  收藏 所属分类: hibernate

FeedBack:
# re: hibernate 映射自身一对多双相关联[未登录] 2014-06-20 09:03 1
楼主还在富士康?  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: