简体   繁体   中英

JPA - how to replicate update versioned query of Hibernate in openjpa

I'm trying to replicate the behavior of "update versioned" of Hibernate in Openjpa:

em.createQuery("update versioned MyEntity m set m.otherEntity=null where m.otherEntity=:otherEntity).setParameter("otherEntity", otherEntity).executeUpdate();

I tried the same query in openjpa but i'm getting a error for this query (it takes the "versioned" as a alias), so its clearly a HQL feature.

Hibernate spec:

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.

so HQL has the option to use the update versioned to reset version however in 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM