KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > UnresolvableObjectException


1 //$Id: UnresolvableObjectException.java,v 1.4 2005/02/12 07:19:50 steveebersole Exp $
2
package org.hibernate;
3
4 import java.io.Serializable JavaDoc;
5
6 import org.hibernate.pretty.MessageHelper;
7
8 /**
9  * 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 JavaDoc identifier;
17     private final String JavaDoc entityName;
18
19     public UnresolvableObjectException(Serializable JavaDoc identifier, String JavaDoc clazz) {
20         this("No row with the given identifier exists", identifier, clazz);
21     }
22     UnresolvableObjectException(String JavaDoc message, Serializable JavaDoc identifier, String JavaDoc clazz) {
23         super(message);
24         this.identifier = identifier;
25         this.entityName = clazz;
26     }
27     public Serializable JavaDoc getIdentifier() {
28         return identifier;
29     }
30
31     public String JavaDoc getMessage() {
32         return super.getMessage() + ": " +
33             MessageHelper.infoString(entityName, identifier);
34     }
35
36     public String JavaDoc getEntityName() {
37         return entityName;
38     }
39
40     public static void throwIfNull(Object JavaDoc o, Serializable JavaDoc id, String JavaDoc clazz)
41     throws UnresolvableObjectException {
42         if (o==null) throw new UnresolvableObjectException(id, clazz);
43     }
44
45 }
46
47
48
49
50
51
52
53
Popular Tags