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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With