Talha Ahmed Khan
Talha Ahmed Khan

Reputation: 15433

Hibernate Serialize/Deserialize Object and save it

I have an Object of my POJO Class and I saved it on my Redis (NoSql) server as byte[].

Now I When I get the object back from the Redis server, make some changes and call session.saveOrUpdate(), it throws an exception.

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

I am using SerializationHelper class to serialize() and deserialize() the object and its working fine.

Is there any way in Hibernate that I can save that deserialize object.

Upvotes: 0

Views: 1833

Answers (1)

JB Nizet
JB Nizet

Reputation: 691715

saveOrUpdate() tries to attach a detached (or transient) object to the session.

Since Hibernate guarantees that a session does never holds 2 instances of the same attached entity, it throws this exception.

If you want to copy the state of a detached object to an attached one, use session.merge() (which returns the attached, modified object).

Upvotes: 1

Related Questions