NonUniqueObjectException
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session首先看看這個類:
//$Id: NonUniqueObjectException.java,v 1.4 2005/02/12 07:19:50 steveebersole Exp $
2 package org.hibernate;
3
4 import java.io.Serializable

5
6 import org.hibernate.pretty.MessageHelper;
7
8 /**
9 * This exception is thrown when an operation would
10 * break session-scoped identity. This occurs if the
11 * user tries to associate two different instances of
12 * the same Java class with a particular identifier,
13 * in the scope of a single <tt>Session</tt>.
14 *
15 * @author Gavin King
16 */
17 public class NonUniqueObjectException extends HibernateException {
18 private final Serializable

19 private final String

20
21 public NonUniqueObjectException(String



22 super(message);
23 this.entityName = clazz;
24 this.identifier = id;
25 }
26
27 public NonUniqueObjectException(Serializable


28 this("a different object with the same identifier value was already associated with the session", id, clazz);
29 }
30
31 public Serializable

32 return identifier;
33 }
34
35 public String

36 return super.getMessage() + ": " +
37 MessageHelper.infoString(entityName, identifier);
38 }
39
40 public String

41 return entityName;
42 }
43
44 }
解決方案:
this..getSession().clear();
posted @ 2008-09-25 17:07 bill 閱讀(896) | 評論 (0) | 編輯 收藏