In Oracle we can create an update query that will return the updated record using the RETURNING clause.
Is there similar functionality in Hibernate?
Apart from database-generated values there is obviously no need for Hibernate to return the updated instance because the object passed to Session.saveOrUpdate()
is the updated instance. Database-generated values (sequence, trigger, defaults, etc.) will be set after Session.saveOrUpdate
if they are accordingly annotated (or defined in a XML mapping file).
For identifier values use the JPA @javax.persistence.GeneratedValue
annotation in conjunction with the JPA @javax.persistence.Id
annotation. For simple properties use the native Hibernate @org.hibernate.annotations.Generated
annotation (afaik there is no according JPA annotation).
How generated identifier values are retrieved by Hibernate depends on the generation strategy and/or the database dialect. For simple properties Hibernate executes an additional SELECT
by id statement after the INSERT
or UPDATE
.
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.