在JPA中,有什么方法可以复制Hibernate的saveOrUpdate行为,
saveOrUpdate
public void saveOrUpdate(Object object)
throws HibernateException
Either save(Object) or update(Object) the given instance, depending upon resolution of the unsaved-value checks (see the manual for discussion of unsaved-value checking).
This operation cascades to associated instances if the association is mapped with cascade="save-update".
Parameters:
object - a transient or detached instance containing new or updated state
Throws:
HibernateException
See Also:
save(Object), update(Object)
它实质上检查数据库中是否已存在该对象,并根据需要更新该对象或保存该对象的新实例。
JPA无事务读取很不错,但是Hibernate确实缺少这种方法。有经验的JPA开发人员如何处理此问题?
尝试使用该EntityManager.merge
方法-这非常相似。
Xebia的博客文章中对差异有一个很好的描述:“ JPA实施模式:保存(独立)实体”。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句