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

Thursday, 15 June 2017

A different object with the same identifier value was already associated with the session

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

What is the reason of such exception?


Session already contains object that you are trying to put there one more time  with such identifier (for example with update). It also could be many-to-one  or one-to-many relationship object or cascading operation.


How to deal with it?

  • probably you already called update() for this object, and trying do this 2nd time
  • another possible reason you making copy of the object that is already associated with session (has assigned id and was loaded recently) and trying to update it
  • try session.merge() - it will copy the state of the given object into the persistent object with the same identifier.
  • try session.evict(object) - remove this instance from the session cache.

Tuesday, 21 February 2012

C3P0 ConnectionPool: How To configure

C3P0 - is connection pool,  connection pool is a cache of database connections maintained, so that the connections can be reused when future requests to the database are required. 


The main question is how to cofigure it, because default values are not perfect. First of all I found oficial doc with description of the values. Next I found this one C3P0 ConnectionPool Configuration Rules of Thumb. After some performance testing of my application, I can confirm that configuring like in this article, can greatly increase your performance, in my case it was about twice. So bellow text of this article -  "

Sunday, 12 December 2010

JavaEE : Hibernate tutorial


Hibernate is an object-relational mapping (ORM) library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database.