I have a JPA/Hibernate object which uses a composite key as the primary key. I am trying to read the object from the database and make an update.
Lets say the primary key is (id and name) and the following rows exist in the database.
1 john London
2 bob Birmingham
3 Dave Kent
If i load an object using the key (1,john) then everything works fine. If i load it using the same primary but with a difference case using (1, John) then i get the following exception:
org.hibernate.HibernateException: identifier of an instance of Document was altered from com.myPck.test1.documentsPK[ Id=1, msgOwner=john ] to com.myPck.test1.documentsPK[ Id=1, msgOwner=John ];
After i load the row i do update it using JPQL but i dont update any of the primary key columns. Interestingly if i search for a row that does not exist i dont get that exception. It only occurs if i search for a row that does exist but the case used on the key is different from what is actually in the database.
What could be causing this and how do i resolve it?
Thanks
Can you post the code for the Compound Key class that you are using. My guess is that you have a badly implemented equals and hashCode method on the compound primary key class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.