01: //$Id: NonUniqueObjectException.java 5685 2005-02-12 07:19:50Z steveebersole $
02: package org.hibernate;
03:
04: import java.io.Serializable;
05:
06: import org.hibernate.pretty.MessageHelper;
07:
08: /**
09: * 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 identifier;
19: private final String entityName;
20:
21: public NonUniqueObjectException(String message, Serializable id,
22: String clazz) {
23: super (message);
24: this .entityName = clazz;
25: this .identifier = id;
26: }
27:
28: public NonUniqueObjectException(Serializable id, String clazz) {
29: this (
30: "a different object with the same identifier value was already associated with the session",
31: id, clazz);
32: }
33:
34: public Serializable getIdentifier() {
35: return identifier;
36: }
37:
38: public String getMessage() {
39: return super .getMessage() + ": "
40: + MessageHelper.infoString(entityName, identifier);
41: }
42:
43: public String getEntityName() {
44: return entityName;
45: }
46:
47: }
|