Code:
// persistence context started
User newUser = new User(userName, Encoder.encodePassword(password));
this.session.save(newUser);
Type newTypeIn = new Type("new type", newUser, 'I');
this.session.save(newTypeIn);
Type newTypeOut = new Type("new type", newUser, 'O');
this.session.save(newTypeOut);
// transaction commit and persistence context end
Then got a Exception:org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [entities.Type#0]
I read the book <<Java Persistence With Hibernate>>, It said, this Exception is because the detached Object was reattached in Session but there was already another Object with the same identifier in the Session. The solution is use session.merge() instead of session.update(). But that's not my Situation, my problem is about new created Object, so what should I do?
Thanks!