org.hibernate.type
Class EntityType

java.lang.Object
  extended byorg.hibernate.type.AbstractType
      extended byorg.hibernate.type.EntityType
All Implemented Interfaces:
AssociationType, Serializable, Type
Direct Known Subclasses:
ManyToOneType, OneToOneType

public abstract class EntityType
extends AbstractType
implements AssociationType

A reference to an entity class

Author:
Gavin King
See Also:
Serialized Form

Field Summary
protected  boolean isEmbeddedInXML
           
protected  String uniqueKeyPropertyName
           
 
Constructor Summary
protected EntityType(String entityName, String uniqueKeyPropertyName, boolean eager, boolean isEmbeddedInXML, boolean unwrapProxy)
           
 
Method Summary
 int compare(Object x, Object y, EntityMode entityMode)
          compare two instances of the type
 Object deepCopy(Object value, EntityMode entityMode, SessionFactoryImplementor factory)
          Return a deep copy of the persistent state, stopping at entities and at collections.
 Object fromXMLNode(org.dom4j.Node xml, Mapping factory)
          Parse the XML representation of an instance.
 String getAssociatedEntityName()
           
 String getAssociatedEntityName(SessionFactoryImplementor factory)
          Get the entity name of the associated entity
 Joinable getAssociatedJoinable(SessionFactoryImplementor factory)
          Get the "persister" for this association - a class or collection persister
 int getHashCode(Object x, EntityMode entityMode, SessionFactoryImplementor factory)
          Get a hashcode, consistent with persistence "equality"
protected  Object getIdentifier(Object value, SessionImplementor session)
           
 String getIdentifierOrUniqueKeyPropertyName(Mapping factory)
           
 Type getIdentifierOrUniqueKeyType(Mapping factory)
           
 String getLHSPropertyName()
          Get the name of a property in the owning entity that provides the join key (null if the identifier)
 String getName()
          Returns the abbreviated name of the type.
 String getOnCondition(String alias, SessionFactoryImplementor factory, Map enabledFilters)
          Get the "filtering" SQL fragment that is applied in the SQL on clause, in addition to the usual join condition
 String getPropertyName()
           
 Class getReturnedClass()
          This returns the wrong class for an entity with a proxy, or for a named entity.
 String getRHSUniqueKeyPropertyName()
          The name of a unique property of the associated entity that provides the join key (null if the identifier of an entity, or key of a collection)
 Type getSemiResolvedType(SessionFactoryImplementor factory)
          Get the type of a semi-resolved value.
 boolean isAssociationType()
          Return true if the implementation is castable to AssociationType.
 boolean isEmbeddedInXML()
           
 boolean isEntityType()
          Is this type an entity type?
 boolean isEqual(Object x, Object y, EntityMode entityMode, SessionFactoryImplementor factory)
          Compare two instances of the class mapped by this type for persistence "equality" - equality of persistent state.
 boolean isMutable()
          Are objects of this type mutable.
protected  boolean isNotEmbedded(SessionImplementor session)
           
protected  boolean isNull(Object owner, SessionImplementor session)
           
protected abstract  boolean isNullable()
           
abstract  boolean isOneToOne()
           
 boolean isReferenceToPrimaryKey()
          Does this association foreign key reference the primary key of the other table?
 boolean isSame(Object x, Object y, EntityMode entityMode)
          Compare two instances of the class mapped by this type for persistence "equality" - equality of persistent state - taking a shortcut for entity references.
 boolean isXMLElement()
           
 Object loadByUniqueKey(String entityName, String uniqueKeyPropertyName, Object key, SessionImplementor session)
          Load an instance by a unique key that is not the primary key.
 Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
          Retrieve an instance of the mapped class from a JDBC resultset.
 Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner)
          Retrieve an instance of the mapped class from a JDBC resultset.
 Object replace(Object original, Object target, SessionImplementor session, Object owner, Map copyCache)
          During merge, replace the existing (target) value in the entity we are merging to with a new (original) value from the detached entity we are merging.
 Object resolve(Object value, SessionImplementor session, Object owner)
          Resolve an identifier or unique key value
protected  Object resolveIdentifier(Serializable id, SessionImplementor session)
          Resolve an identifier
 void setToXMLNode(org.dom4j.Node node, Object value, SessionFactoryImplementor factory)
          A representation of the value to be embedded in an XML element.
 String toLoggableString(Object value, SessionFactoryImplementor factory)
          A representation of the value to be embedded in a log file.
 String toString()
           
 
Methods inherited from class org.hibernate.type.AbstractType
assemble, beforeAssemble, disassemble, getHashCode, hydrate, isAnyType, isCollectionType, isComponentType, isDirty, isEqual, isModified, replace, replaceNode, semiResolve
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.hibernate.type.AssociationType
getForeignKeyDirection, isAlwaysDirtyChecked, useLHSPrimaryKey
 
Methods inherited from interface org.hibernate.type.Type
assemble, beforeAssemble, disassemble, getColumnSpan, getHashCode, hydrate, isAnyType, isCollectionType, isComponentType, isDirty, isDirty, isEqual, isModified, nullSafeSet, nullSafeSet, replace, semiResolve, sqlTypes, toColumnNullness
 

Field Detail

uniqueKeyPropertyName

protected final String uniqueKeyPropertyName

isEmbeddedInXML

protected final boolean isEmbeddedInXML
Constructor Detail

EntityType

protected EntityType(String entityName,
                     String uniqueKeyPropertyName,
                     boolean eager,
                     boolean isEmbeddedInXML,
                     boolean unwrapProxy)
Method Detail

isEmbeddedInXML

public boolean isEmbeddedInXML()
Specified by:
isEmbeddedInXML in interface AssociationType

isEntityType

public final boolean isEntityType()
Description copied from interface: Type
Is this type an entity type?

Specified by:
isEntityType in interface Type
Overrides:
isEntityType in class AbstractType

getPropertyName

public String getPropertyName()

getAssociatedEntityName

public final String getAssociatedEntityName()

isSame

public final boolean isSame(Object x,
                            Object y,
                            EntityMode entityMode)
Description copied from interface: Type
Compare two instances of the class mapped by this type for persistence "equality" - equality of persistent state - taking a shortcut for entity references.

Specified by:
isSame in interface Type
Overrides:
isSame in class AbstractType

compare

public int compare(Object x,
                   Object y,
                   EntityMode entityMode)
Description copied from interface: Type
compare two instances of the type

Specified by:
compare in interface Type
Overrides:
compare in class AbstractType

nullSafeGet

public Object nullSafeGet(ResultSet rs,
                          String name,
                          SessionImplementor session,
                          Object owner)
                   throws HibernateException,
                          SQLException
Description copied from interface: Type
Retrieve an instance of the mapped class from a JDBC resultset. Implementations should handle possibility of null values. This method might be called if the type is known to be a single-column type.

Specified by:
nullSafeGet in interface Type
Parameters:
rs -
name - the column name
session -
owner - the parent entity
Returns:
Object
Throws:
SQLException
HibernateException

getReturnedClass

public final Class getReturnedClass()
This returns the wrong class for an entity with a proxy, or for a named entity. Theoretically it should return the proxy class, but it doesn't.

Specified by:
getReturnedClass in interface Type
Returns:
Class

getIdentifier

protected final Object getIdentifier(Object value,
                                     SessionImplementor session)
                              throws HibernateException
Throws:
HibernateException

isNotEmbedded

protected boolean isNotEmbedded(SessionImplementor session)

toLoggableString

public String toLoggableString(Object value,
                               SessionFactoryImplementor factory)
                        throws HibernateException
Description copied from interface: Type
A representation of the value to be embedded in a log file.

Specified by:
toLoggableString in interface Type
Parameters:
value -
factory -
Returns:
String
Throws:
HibernateException

getName

public String getName()
Description copied from interface: Type
Returns the abbreviated name of the type.

Specified by:
getName in interface Type
Returns:
String the Hibernate type name

deepCopy

public Object deepCopy(Object value,
                       EntityMode entityMode,
                       SessionFactoryImplementor factory)
Description copied from interface: Type
Return a deep copy of the persistent state, stopping at entities and at collections.

Specified by:
deepCopy in interface Type
Parameters:
value - generally a collection element or entity field
entityMode -
factory -
Returns:
Object a copy

isMutable

public boolean isMutable()
Description copied from interface: Type
Are objects of this type mutable. (With respect to the referencing object ... entities and collections are considered immutable because they manage their own internal state.)

Specified by:
isMutable in interface Type
Returns:
boolean

isOneToOne

public abstract boolean isOneToOne()

replace

public Object replace(Object original,
                      Object target,
                      SessionImplementor session,
                      Object owner,
                      Map copyCache)
               throws HibernateException
Description copied from interface: Type
During merge, replace the existing (target) value in the entity we are merging to with a new (original) value from the detached entity we are merging. For immutable objects, or null values, it is safe to simply return the first parameter. For mutable objects, it is safe to return a copy of the first parameter. For objects with component values, it might make sense to recursively replace component values.

Specified by:
replace in interface Type
Parameters:
original - the value from the detached entity being merged
target - the value in the managed entity
Returns:
the value to be merged
Throws:
HibernateException

isAssociationType

public boolean isAssociationType()
Description copied from interface: Type
Return true if the implementation is castable to AssociationType. This does not necessarily imply that the type actually represents an association.

Specified by:
isAssociationType in interface Type
Overrides:
isAssociationType in class AbstractType

nullSafeGet

public final Object nullSafeGet(ResultSet rs,
                                String[] names,
                                SessionImplementor session,
                                Object owner)
                         throws HibernateException,
                                SQLException
Description copied from interface: Type
Retrieve an instance of the mapped class from a JDBC resultset. Implementors should handle possibility of null values.

Specified by:
nullSafeGet in interface Type
Parameters:
rs -
names - the column names
session -
owner - the parent entity
Returns:
Object
Throws:
HibernateException
SQLException
See Also:
alternative, 2-phase property initialization

getAssociatedJoinable

public Joinable getAssociatedJoinable(SessionFactoryImplementor factory)
                               throws MappingException
Description copied from interface: AssociationType
Get the "persister" for this association - a class or collection persister

Specified by:
getAssociatedJoinable in interface AssociationType
Throws:
MappingException

getIdentifierOrUniqueKeyType

public final Type getIdentifierOrUniqueKeyType(Mapping factory)
                                        throws MappingException
Throws:
MappingException

getIdentifierOrUniqueKeyPropertyName

public final String getIdentifierOrUniqueKeyPropertyName(Mapping factory)
                                                  throws MappingException
Throws:
MappingException

isNullable

protected abstract boolean isNullable()

resolveIdentifier

protected final Object resolveIdentifier(Serializable id,
                                         SessionImplementor session)
                                  throws HibernateException
Resolve an identifier

Throws:
HibernateException

isNull

protected boolean isNull(Object owner,
                         SessionImplementor session)

resolve

public Object resolve(Object value,
                      SessionImplementor session,
                      Object owner)
               throws HibernateException
Resolve an identifier or unique key value

Specified by:
resolve in interface Type
Overrides:
resolve in class AbstractType
Throws:
HibernateException

getAssociatedEntityName

public String getAssociatedEntityName(SessionFactoryImplementor factory)
Description copied from interface: AssociationType
Get the entity name of the associated entity

Specified by:
getAssociatedEntityName in interface AssociationType

isReferenceToPrimaryKey

public boolean isReferenceToPrimaryKey()
Does this association foreign key reference the primary key of the other table?


getRHSUniqueKeyPropertyName

public String getRHSUniqueKeyPropertyName()
Description copied from interface: AssociationType
The name of a unique property of the associated entity that provides the join key (null if the identifier of an entity, or key of a collection)

Specified by:
getRHSUniqueKeyPropertyName in interface AssociationType

toString

public String toString()

loadByUniqueKey

public Object loadByUniqueKey(String entityName,
                              String uniqueKeyPropertyName,
                              Object key,
                              SessionImplementor session)
                       throws HibernateException
Load an instance by a unique key that is not the primary key.

Throws:
HibernateException

getLHSPropertyName

public String getLHSPropertyName()
Description copied from interface: AssociationType
Get the name of a property in the owning entity that provides the join key (null if the identifier)

Specified by:
getLHSPropertyName in interface AssociationType

getOnCondition

public String getOnCondition(String alias,
                             SessionFactoryImplementor factory,
                             Map enabledFilters)
                      throws MappingException
Description copied from interface: AssociationType
Get the "filtering" SQL fragment that is applied in the SQL on clause, in addition to the usual join condition

Specified by:
getOnCondition in interface AssociationType
Throws:
MappingException

getSemiResolvedType

public Type getSemiResolvedType(SessionFactoryImplementor factory)
Description copied from interface: Type
Get the type of a semi-resolved value.

Specified by:
getSemiResolvedType in interface Type
Overrides:
getSemiResolvedType in class AbstractType

getHashCode

public int getHashCode(Object x,
                       EntityMode entityMode,
                       SessionFactoryImplementor factory)
Description copied from interface: Type
Get a hashcode, consistent with persistence "equality"

Specified by:
getHashCode in interface Type
Overrides:
getHashCode in class AbstractType

isEqual

public boolean isEqual(Object x,
                       Object y,
                       EntityMode entityMode,
                       SessionFactoryImplementor factory)
Description copied from interface: Type
Compare two instances of the class mapped by this type for persistence "equality" - equality of persistent state.

Specified by:
isEqual in interface Type
Overrides:
isEqual in class AbstractType

isXMLElement

public boolean isXMLElement()
Specified by:
isXMLElement in interface Type
Overrides:
isXMLElement in class AbstractType

fromXMLNode

public Object fromXMLNode(org.dom4j.Node xml,
                          Mapping factory)
                   throws HibernateException
Description copied from interface: Type
Parse the XML representation of an instance.

Specified by:
fromXMLNode in interface Type
Parameters:
xml -
factory -
Returns:
an instance of the type
Throws:
HibernateException

setToXMLNode

public void setToXMLNode(org.dom4j.Node node,
                         Object value,
                         SessionFactoryImplementor factory)
                  throws HibernateException
Description copied from interface: Type
A representation of the value to be embedded in an XML element.

Specified by:
setToXMLNode in interface Type
Parameters:
value -
factory -
Returns:
String
Throws:
HibernateException