【发布时间】:2010-11-11 11:43:57
【问题描述】:
在JPA中,有什么方法可以复制Hibernate的saveOrUpdate behavior,
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 开发人员如何处理这个问题?
【问题讨论】:
-
检查“主键”是否为空怎么办?
标签: java hibernate jpa persistence