Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does the update method work for Hibernate Session?

 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Can anyone tell me how the update method works for Hibernate Session?

If I pass in a POJO (which has a corresponding table in the DB) does hibernate check which fields are different from the DB and only updates only the columns which have changed or does it to a blanket update of all columns in the table.

Thanks for any help.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe you'll get a blanket update. The update is really more of a differentiation from save. Essentially, you know that Hibernate will not create a new record in the database.

-Cameron McKenzie
 
Christian Dillinger
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your entity is bound to the session, hibernate "knows" when it gets changed. By default every field is updated. But you can change that behaviour and use "dynamic update" which can save some time. E.g. when you have some large fields or blobs/clobs in your table.
I didn't check but (I think) if you want dynamic-update and the POJO isn't bound to the session hibernate does a SELECT and then creates an update.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic