[Fixed] Hibernate Error: a different object with the same identifier value was already associated with the session

Before:


public boolean updateUserStory(UserStory userStory) {
try {
Session session = sessionFactory.getCurrentSession();
session.update(userStory);
return true;
} catch (HibernateException e) {
e.printStackTrace();
return false;
}

}

After:

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public boolean updateUserStory(UserStory userStory) {
try {
Session session = sessionFactory.getCurrentSession();
session.merge(userStory);
return true;
} catch (HibernateException e) {
e.printStackTrace();
return false;
}

}

References:

[1]. http://stackoverflow.com/questions/3265765/hibernate-a-different-object-with-the-same-identifier-value-was-already-associ

[2]. http://stackoverflow.com/questions/10849974/a-different-object-with-the-same-identifier-value-was-already-associated-with-th

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s