hibernate ORM 配置

本文详细阐述了企业人员信息管理系统的实现原理,包括人员、单位及人员单位关联表的设计,以及如何利用Hibernate进行实体关联与数据映射。重点介绍了Tac01、Tac20和Tace10实体类的定义与操作,以及获取人员单位信息的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Tac01  人员信息表

Tac20  人员单位关联表

Tace10  单位信息表

  人员可能会对应多个单位 ,用有效标志区分,一个单位会有多个人员

    Tac01.hbm.xml  ,      一对多(one  to  many)

 <class name="com.ssh.test.hiber.po.Tac01" table="TAC01" schema="SICP3">
        <comment>人员</comment>
        <id name="aac001" type="java.lang.Long">
            <column name="AAC001" precision="20" scale="0" />
            <generator class="assigned" />
        </id>
        <property name="aac003" type="java.lang.String">
            <column name="AAC003" length="50">
                <comment>姓名</comment>
            </column>
        </property>
        <property name="aac004" type="java.lang.String">
            <column name="AAC004" length="1">
                <comment>性别</comment>
            </column>
        </property>
        <property name="aac006" type="java.lang.Integer">
            <column name="AAC006" precision="8" scale="0">
                <comment>出生日期</comment>
            </column>
        </property>
        <property name="aac007" type="java.lang.Integer">
            <column name="AAC007" precision="8" scale="0">
                <comment>工作日期</comment>
            </column>
        </property>
         <set name="tac20s" inverse="true" lazy="false">
            <key>
                <column name="AAC001" />
            </key>
            <one-to-many class="com.ssh.test.hiber.po.Tac20" />
        </set>
    </class>


Tac01 .java

 

	private static final long serialVersionUID = 1L;
	private Long aac001;
	private String aac003;
	private String aac004;
	private Integer aac006;
	private Integer aac007;
	private Set<Tac20> tac20s = new HashSet<Tac20>() ;


          get,set   删除 ,自己增加

 

Tac20.hbm.xml     两个   多对一 ( many  to one)

 <class name="com.ssh.test.hiber.po.Tac20" table="TAC20" schema="SICP3">
        <comment>人员单位关联表</comment>
        <id name="aaz157" type="java.lang.Long">
            <column name="AAZ157" precision="16" scale="0" />
            <generator class="assigned" />
        </id>
        <many-to-one name="ac01" class="com.ssh.test.hiber.po.Tac01" fetch="select" lazy="false" insert="false" update="false">
            <column name="AAC001" />
        </many-to-one>
        <many-to-one name="ae10" class="com.ssh.test.hiber.po.Tace10" fetch="select" lazy="false" insert="false" update="false">
            <column name="AAB001" />
        </many-to-one>
        <property name="aac066" type="java.lang.String">
            <column name="AAC066" length="3">
                <comment></comment>
            </column>
        </property>
        <property name="aab001" type="java.lang.Long">
            <column name="AAB001" precision="20" scale="0">
                <comment>单位ID</comment>
            </column>
        </property>
        <property name="aac001" type="java.lang.Long">
            <column name="AAC001" precision="20" scale="0">
                <comment>人员ID</comment>
            </column>
        </property>
        <property name="aac013" type="java.lang.String">
            <column name="AAC013" length="1">
                <comment></comment>
            </column>
        </property>
        <property name="aac031" type="java.lang.String">
            <column name="AAC031" length="1">
                <comment>有效标记</comment>
            </column>
        </property>
        <property name="aae030" type="java.lang.Integer">
            <column name="AAE030" precision="8" scale="0">
                <comment>开始日期</comment>
            </column>
        </property>
        <property name="aae031" type="java.lang.Integer">
            <column name="AAE031" precision="8" scale="0">
                <comment>终止日期</comment>
            </column>
        </property>
    </class>


Tac20.java

private Long aaz157;
	private String aac066;
	private Long aab001;
	private Long aac001;
	private String aac013;
	private String aac031;
	private Integer aae030;
	private Integer aae031;
	private Tac01 ac01;
	private Tace10 ae10;


Tace10 .hbm.xml     一对多 (one   to  many)

<class name="com.ssh.test.hiber.po.Tace10" table="TACE10" schema="SICP3">
        <comment>单位</comment>
        <id name="aaz001" type="java.lang.Long">
            <column name="AAZ001" precision="20" scale="0" />
            <generator class="assigned" />
        </id>
        <property name="aae004" type="java.lang.String">
            <column name="AAE004" length="50">
                <comment>联系人姓名</comment>
            </column>
        </property>
        <property name="aae005" type="java.lang.String">
            <column name="AAE005" length="20">
                <comment>联系电话</comment>
            </column>
        </property>
        <property name="aae006" type="java.lang.String">
            <column name="AAE006" length="100">
                <comment>地址</comment>
            </column>
        </property>
        <property name="aab069" type="java.lang.String">
            <column name="AAB069" length="100">
                <comment>名称</comment>
            </column>
        </property>
        <set name="ac20s" inverse="true">
            <key>
                <column name="AAZ001" />
            </key>
            <one-to-many class="com.ssh.test.hiber.po.Tac20" />
        </set>
    </class>


 Tace10.java

private Long aaz001;
	private String aae004;
	private String aae005;
	private String aae006;
	private String aab069;
	private Set<Tac20> ac20s = new HashSet<Tac20>() ;


取值时,我们只用 hibernateTemplate.get(Tac01.class, aac001)  取到  Tac01  ,

就可以通过  

                       Tac01   ac01 = hibernateTemplate.get(Tac01.class, aac001) ;

	if(ac01 != null && ac01.getAac003() != null){
			if(ac01.getTac20s() != null){
				for(Tac20 ac20 : ac01.getTac20s()){
					dto.setAab069(ac20.getAe10().getAab069());
				}
			}else{
				dto.setAab069("人员暂时没有单位");
			}
			dto.setName(ac01.getAac003());
		}else{
			dto.setName("人员不存在");
		}

 

 

代码示例      http://download.youkuaiyun.com/detail/meililiuwei/6857577
 

 

 

 

 

 

 

 

 

 

 

 

      

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值