JPA - 如何在 openjpa 中复制 Hibernate 的更新版本化查询
JPA - how to replicate update versioned query of Hibernate in openjpa
我正在尝试在 Openjpa 中复制 Hibernate "update versioned" 的行为:
em.createQuery("update versioned MyEntity m set m.otherEntity=null where m.otherEntity=:otherEntity).setParameter("otherEntity", otherEntity).executeUpdate();
我在 openjpa 中尝试了相同的查询,但此查询出现错误(它使用 "versioned" 作为别名),因此它显然是一个 HQL 功能。
Hibernate 规范:
In keeping with the EJB3 specification, HQL UPDATE statements, by default, do not effect the version or the timestamp property values for the affected entities. However, you can force Hibernate to reset the version or timestamp property values through the use of a versioned update. This is achieved by adding the VERSIONED keyword after the UPDATE keyword.
因此 HQL 可以选择使用 更新版本 来重置版本
然而在 OpenJpa 中:
Bulk update maps directly to a database update operation, bypassing optimistic locking checks. Portable applications must manually update the value of the version column, if desired, and/or manually validate the value of the version column.
我正在尝试在 Openjpa 中复制 Hibernate "update versioned" 的行为:
em.createQuery("update versioned MyEntity m set m.otherEntity=null where m.otherEntity=:otherEntity).setParameter("otherEntity", otherEntity).executeUpdate();
我在 openjpa 中尝试了相同的查询,但此查询出现错误(它使用 "versioned" 作为别名),因此它显然是一个 HQL 功能。
Hibernate 规范:
In keeping with the EJB3 specification, HQL UPDATE statements, by default, do not effect the version or the timestamp property values for the affected entities. However, you can force Hibernate to reset the version or timestamp property values through the use of a versioned update. This is achieved by adding the VERSIONED keyword after the UPDATE keyword.
因此 HQL 可以选择使用 更新版本 来重置版本 然而在 OpenJpa 中:
Bulk update maps directly to a database update operation, bypassing optimistic locking checks. Portable applications must manually update the value of the version column, if desired, and/or manually validate the value of the version column.