在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开发人员如何处理这种情况?