把session.saveOrUpdate(role); 改为
session.merge(role); 就搞定了
官方的user faq
I called saveOrUpdate() or update() and got a NonUniqueObjectException!
The session maintains a unique mapping between persistent identity and object instance, in order to help you avoid data aliasing problems. You cannot simultaneously attach two objects with the same class and identifier to the same session.
The best way to avoid any possibility of this exception is to always call saveOrUpdate() at the beginning of the transaction, when the session is empty.
In Hibernate3, you can try using the merge() operation, which does not reattach the passed instance
session.merge(role); 就搞定了
官方的user faq
I called saveOrUpdate() or update() and got a NonUniqueObjectException!
The session maintains a unique mapping between persistent identity and object instance, in order to help you avoid data aliasing problems. You cannot simultaneously attach two objects with the same class and identifier to the same session.
The best way to avoid any possibility of this exception is to always call saveOrUpdate() at the beginning of the transaction, when the session is empty.
In Hibernate3, you can try using the merge() operation, which does not reattach the passed instance