Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate: How to fix "identifier of an instance altered from X to Y"?

org.hibernate.HibernateException: identifier of an instance 
of org.cometd.hibernate.User altered from 12 to 3

in fact, my user table is really must dynamically change its value, my Java app is multithreaded. Any ideas how to fix it?

like image 478
gennad Avatar asked Nov 14 '10 19:11

gennad


3 Answers

Are you changing the primary key value of a User object somewhere? You shouldn't do that. Check that your mapping for the primary key is correct.

What does your mapping XML file or mapping annotations look like?

like image 53
Juha Syrjälä Avatar answered Oct 21 '22 16:10

Juha Syrjälä


You must detach your entity from session before modifying its ID fields

like image 35
Danubian Sailor Avatar answered Oct 21 '22 16:10

Danubian Sailor


In my case, the PK Field in hbm.xml was of type "integer" but in bean code it was long.

like image 17
Muhammad Hewedy Avatar answered Oct 21 '22 16:10

Muhammad Hewedy