Hibernate克隆对象

  

如果有两个MODEL(A,A_log) ,A_log包含A的所有元素(包括A的ID),A_log唯一多的字段是自己的ID,那么在想在修改A之前的时候记录他的结果到A_log表中。可以这样写:

 

可以在A_log的MODEL中加一行:private A a;(set,get方法)

然后在A_log.xml中这样写:

 

<hibernate-mapping>
    <class name="ie.cdclab.detect.eruption.model.LabEruptionBDectctLog" table="LAB_ERUPTION_B_DECTCT_LOG" schema="LAB">
        <comment>发热伴出疹细菌检测表_log。</comment>
        <id name="idEruptionBDectctLog" type="java.lang.String">
            <column name="ID_ERUPTION_B_DECTCT_LOG" length="40" />
            <generator class="uuid" />
        </id>
                <component name="labEruptionBDetect">   --用这个把相同的元素包起来,labEruptionBDetect是原表
        <property name="idEruptionBDectct" type="java.lang.String">
            <column name="ID_ERUPTION_B_DECTCT" length="40" not-null="true">
                <comment>发热伴出疹细菌检测表ID。</comment>
            </column>
        </property>
        <property name="idSampleinfo" type="java.lang.String">
            <column name="ID_SAMPLEINFO" length="40" not-null="true">
                <comment>标本信息ID。</comment>
            </column>
        </property>
        </component>
    </class>
</hibernate-mapping>

 

然后在service中:

 

	public void saveLog(LabEruptionBDetect LabEruptionBDetect) {
		// TODO Auto-generated method stub
		
		LabEruptionBDectctLog LabEruptionBDetectLog = new LabEruptionBDectctLog();
		LabEruptionBDetectLog.setLabEruptionBDetect(LabEruptionBDetect);
		dao.save(LabEruptionBDetectLog);
	}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值