Các bài viết cũ

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

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

https://tranduythanh.com

Các bài viết mới đã được cập nhật trên https://tranduythanh.com

Tôi IT - Change the world

Research + Technical -> Programming,

VN.NVANHUONG

No Pain No Gain

Study and Share's Blog

Việt Nam tươi đẹp...

Broly

One of the best way to learn is by writing to the paper.