Showing posts with label hibernate. Show all posts
Showing posts with label hibernate. Show all posts

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

This is because, there is already an object with the same primary key in the hibernate session.
Unless it is detached from the session, it wont allow another object with the same primary key.

This case pretty commonly comes when we use SaveOrUpdate() method.
Use Merge() method instead in this case.

A nice write up on this.
http://www.stevideter.com/2008/12/07/saveorupdate-versus-merge-in-hibernate/

Generate HQL pojo classes automatically using hibernate tools

Install the hibernate tools from
http://www.blogger.com/img/blank.gif

Once installed, open the hibernate perspective and then generate a reverse cfg file from the existing (if you have one) or create a new by connecting to the db.

and then create a pakage, go to -> run-> hibernate code generation and create all the required tables and files with or without annotations.

refer:

http://shivasoft.in/blog/sql/myqsl/step-by-step-hibernate-tutorial-using-eclipse-wtp/