hibernate 联合主键类无法批量保存到数据库的问题

昨天使用hibernate循环批量保存一个联合主键类报出如下错误:
AbstractFlushingEventListener[line:301}: Could not synchronize database state with session
Could not execute JDBC batch update

联合主键类配置如下:
<hibernate-mapping>
<class name="com.vcmchina.credithour.model.SzGcEvaResult" table="sz_gc_eva_result" >
<composite-id name="id" class="com.vcmchina.credithour.model.SzGcEvaResultId">
<key-property name="stuNo" type="java.lang.String">
<column name="stu_no" length="20" />
</key-property>
<key-property name="projectCode" type="java.lang.String">
<column name="project_code" length="20" />
</key-property>
<key-property name="weekNo" type="java.lang.Integer">
<column name="week_no" />
</key-property>
<key-property name="syCode" type="java.lang.String">
<column name="sy_code" length="20" />
</key-property>
<key-property name="semSection" type="java.lang.String">
<column name="sem_section" length="10" />
</key-property>
<key-property name="suNo" type="java.lang.String">
<column name="su_no" length="20" />
</key-property>
<key-property name="semNo" type="java.lang.String">
<column name="sem_no" length="20" />
</key-property>
</composite-id>
<property name="secType" type="java.lang.String">
<column name="sec_type" length="10" not-null="true" />
</property>
<property name="graType" type="java.lang.String">
<column name="gra_type" length="10" not-null="true" />
</property>
<property name="semFlag" type="java.lang.String">
<column name="sem_flag" length="10" not-null="true" />
</property>
<property name="evaScore" type="java.lang.Integer">
<column name="eva_score" not-null="true" />
</property>
<property name="recordData" type="java.lang.String">
<column name="record_data" length="30" not-null="true" />
</property>
<property name="empName" type="java.lang.String">
<column name="emp_name" length="50" not-null="true" />
</property>
</class>
</hibernate-mapping>



开始采用的是
public void addSzGcEvaResult(SzGcEvaResult evaResult) {
// TODO Auto-generated method stub
this.getHibernateTemplate().save(evaResult);
}

后来改用merge方法就没有问题了:
public void addSzGcEvaResult(SzGcEvaResult evaResult) {
// TODO Auto-generated method stub
this.getHibernateTemplate().merge(evaResult);
}

我感觉是对象状态的问题,因为我给对象实例化了联合主键,hibernate 认为它不再是瞬态,而是托管状态。
save() --瞬态状态调用,状态变为持久(POJO)
merge()--脱管状态时候调用,状态不变
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值