01: //$Id: UnresolvableObjectException.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: * Thrown when Hibernate could not resolve an object by id, especially when
10: * loading an association.
11: *
12: * @author Gavin King
13: */
14: public class UnresolvableObjectException extends HibernateException {
15:
16: private final Serializable identifier;
17: private final String entityName;
18:
19: public UnresolvableObjectException(Serializable identifier,
20: String clazz) {
21: this ("No row with the given identifier exists", identifier,
22: clazz);
23: }
24:
25: UnresolvableObjectException(String message,
26: Serializable identifier, String clazz) {
27: super (message);
28: this .identifier = identifier;
29: this .entityName = clazz;
30: }
31:
32: public Serializable getIdentifier() {
33: return identifier;
34: }
35:
36: public String getMessage() {
37: return super .getMessage() + ": "
38: + MessageHelper.infoString(entityName, identifier);
39: }
40:
41: public String getEntityName() {
42: return entityName;
43: }
44:
45: public static void throwIfNull(Object o, Serializable id,
46: String clazz) throws UnresolvableObjectException {
47: if (o == null)
48: throw new UnresolvableObjectException(id, clazz);
49: }
50:
51: }
|