如何在JPA中复制Hibernate的saveOrUpdate?

在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实施模式:保存(独立)实体”。

以上是 如何在JPA中复制Hibernate的saveOrUpdate? 的全部内容, 来源链接: utcz.com/qa/419155.html

回到顶部