JPA 跨越EntityManager保存实体.

本文解决使用两个实体管理器(EntityManager)保存实体并修改时出现的错误,通过在persistence.xml中配置openjpa.AutoDetach属性解决。

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

今天打算用2个manager保存实体,一个EM取出实体,并修改,另一个EM保存该实体,但是报了如下错误:


Primary key field com.ibm.eve.core.entity.Vehicle.id of org.apache.openjpa.enhance.com$ibm$eve$core$entity$Vehicle$pcsubclass@6dd36dd3 has non-default value. The instance life cycle is in PNewState state and hence an existing non-default value for the identity field is not permitted. You either need to remove the @GeneratedValue annotation or modify the code to remove the initializer processing.


上网搜索也有很多人问,但是没有答案。

原来答案在persistence.xml的配置当中:在其文件中加入如下property即可:

<property name="openjpa.AutoDetach" value="close, commit, nontx-read"/>


相信一定也有很多人有同样的需求,或者遇到这个问题,确实不好解决,希望帮到你!


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值