如何在JPA中复制Hibernate的saveOrUpdate?
2022-09-01 00:11:35
在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开发人员如何处理这个问题?