org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session
首先看看這個類:
package org.hibernate;
3
4 import java.io.Serializable 
;
5
6 import org.hibernate.pretty.MessageHelper;
7
8
17 public class NonUniqueObjectException
extends HibernateException {
18 private final Serializable 
identifier;
19 private final String 
entityName;
20
21 public NonUniqueObjectException(
String 
message,
Serializable 
id,
String 
clazz) {
22 super(message);
23 this.entityName = clazz;
24 this.identifier = id;
25 }
26
27 public NonUniqueObjectException(
Serializable 
id,
String 
clazz) {
28 this(
"a different object with the same identifier value was already associated with the session", id, clazz);
29 }
30
31 public Serializable 
getIdentifier() {
32 return identifier;
33 }
34
35 public String 
getMessage() {
36 return super.getMessage() +
": " +
37 MessageHelper.infoString(entityName, identifier);
38 }
39
40 public String 
getEntityName() {
41 return entityName;
42 }
43
44 }
解決方案:
this..getSession().clear();
Error Creating SessionFactory java.lang.SecurityException: class"org.apache.commons.collections.SequencedHashMap"'異常的解決方案
本人用 MyEclipse 6.0.0 開發 Struts + Hibernate應用的時候,單獨測試Hibernate的類沒有問題,但是當Web層和Struts整合后,就拋出如下異常:
%%%%Error Creating SessionFactory %%%%
java.lang.SecurityException:
class"org.apache.commons.collections.SequencedHashMap"'s signer
informationdoes not match signer information of other classes in the
same package
原因是myeclipse 6.0的jar包問題。這個是myeclipse沒有做好嚴格的測試。
網上好多人說是commons-collectionsXXX.jar的問題。我也不知道。我是把所有的myeclipse生成的jar都remove buildpath 了。
我又自己添加的jar。就OK!!!!