JPA 跨越EntityManager保存實體.

今天打算用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"/>


相信一定也有很多人有同樣的需求,或者遇到這個問題,確實不好解決,希望幫到你!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章