Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How To know data saved or updated in hibernate session

 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how you know data is updated or saved or deleted in database in hibernate session
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the data programatically?

Not sure I understand why you need to know if it;s an update or an insert - the Hibernate API can be used transparently for either. A delete you will know about, because your code will have deleted an object.
 
Craig Taylor
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Check the id to see if the data has previously been persisted to the database - if it has not then you know it needs to be saved.

Attempt to re-fetch the data based upon it's id; if it doesn't exist then your application (or another) has deleted it - otherwise it's an update if the fetched data and current data differ.

Note : Your question is of the nature that often is because of other problems you're handling ... Why do you want to / need to know?
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am newbie to hibernate. My interviewer asked this question . How you know whether data saved inserted or deleted. what should i reply
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in hibernate session
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic