I'm facing the following error in Hibernate : More than one row with the given identifier was found while I'm trying to merge the object.
I'm using Spring 2.5, Hibernate 3.0 and my application deployed on Websphere ver 7.x
I applied the DB Session per HTTP request methodology (not the spring implementation) but I used the ThreadLocal to save the session to be used again within the current HTTP request, and once the response is ready to be sent to the client I have a HTTPFilter to close any opened session in this Thread.
I got the error once I have a bulk operation on the DB within one HTTP request (Deleting, Updating, Merging, Inserting,.....)
I used the JNDI datasource managed by Websphere itself
I was thinking like following: At the starting point of my request, I asked the session factory to provide me a session instance, and I used this session in my request until I closed it at the end of my request processing. and the hibernate merge method try to load the object before merging it, once the query for loading is executed: the exception is thrown telling me that (More than one row with the given identifier was found), for me this means that the object is loaded to the current session before, so the first stupid idea was to flush and close the current session before merging and start a new one just for this merging, I did that but I faced the same error, that means I was thinking wrong from the beginning.
The second approach I'm trying to follow is to separate this bulk operation to multi operations done directly in separate ajax request (Suppose I have a grid with update and delete functionality for each row, I allow the user to update and delete whatever he wants and I cache these changes until the user click "apply" button to apply all thees changes, the new Idea is: once the user tried to delete a row a new HTTP request (with DB session) will be responsible for deleting this row in the database, in this case no more need to the apply button because the modifications a reflected directly to the DB)
Dear Vijitha Kumara,
Thank you very much for your response, For the ID generation: this table has a composite primary key (Department_Id, Correspondence_Site_Id), both of them is foreign key to another table.
And for your second question: I can't got your idea, could you please repeat it in a clearer way.