4

In Oracle we can create an update query that will return the updated record using the RETURNING clause.

Is there similar functionality in Hibernate?

4
  • Isn't the object after saving already updated? Commented Mar 12, 2012 at 18:25
  • Yes the object saving after the update is already updated. Commented Mar 12, 2012 at 18:32
  • I guess for our case it is more of a design approach. These requests are initiated via webservice calls, which then update the DB. We have decided to return any updated or created object back to the user with the appropriate HTTP status. Within our code we have chosen to track the update up and down the web stack. Commented Mar 12, 2012 at 18:43
  • Then you should just returned the updated instance along with the status code. Commented Mar 12, 2012 at 19:00

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.