`
jimmy.shine
  • 浏览: 389750 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Take care of JPA MERGE

阅读更多

在使用JPA的MERGE的时候要注意:

1、将多执行一次SELECT的操作。

2、Either way will add an entity to a PersistenceContext, the difference is in what you do with the entity afterwards.

Persist takes an entity instance, adds it to the context and makes that instance managed (ie future updates to the entity will be tracked)

Merge creates a new instance of your entity, copies the state from the supplied entity, and makes the new copy managed. The instance you pass in will not be managed (any changes you make will not be part of the transaction - unless you call merge again).

所以,在应当使用PERSIST的时候,绝不应该使用MERGE,一是会带性能的损耗,二是如果后续有使用,尤其有多对一的情况,会带来关联了未保存对象的错误!

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics