[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