org.hibernate.type
Class EntityType

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

public abstract class EntityType
extends AbstractType
implements AssociationType

Base for types which map associations to persistent entities.

See Also:
Serialized Form

Field Summary
protected  boolean isEmbeddedInXML
           
protected  String uniqueKeyPropertyName
           
 
Fields inherited from class org.hibernate.type.AbstractType
LEGACY_DEFAULT_SIZE, LEGACY_DICTATED_SIZE
 
Constructor Summary
protected EntityType(TypeFactory.TypeScope scope, String entityName, boolean referenceToPrimaryKey, String uniqueKeyPropertyName, boolean eager, boolean unwrapProxy)
          Constructs the requested entity type mapping.
protected EntityType(TypeFactory.TypeScope scope, String entityName, String uniqueKeyPropertyName, boolean eager, boolean unwrapProxy)
          Deprecated. Use EntityType(org.hibernate.type.TypeFactory.TypeScope, String, boolean, String, boolean, boolean) instead.
protected EntityType(TypeFactory.TypeScope scope, String entityName, String uniqueKeyPropertyName, boolean eager, boolean isEmbeddedInXML, boolean unwrapProxy)
          Deprecated. Use EntityType(org.hibernate.type.TypeFactory.TypeScope, String, boolean, String, boolean, boolean) instead. See Jira issue: HHH-7771
 
Method Summary
 int compare(Object x, Object y)
          Perform a Comparator style comparison between values
 Object deepCopy(Object value, 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()
          The name of the associated entity.
 String getAssociatedEntityName(SessionFactoryImplementor factory)
          The name of the associated entity.
protected  EntityPersister getAssociatedEntityPersister(SessionFactoryImplementor factory)
           
 Joinable getAssociatedJoinable(SessionFactoryImplementor factory)
          Retrieves the Joinable defining the associated entity.
 int getHashCode(Object x, SessionFactoryImplementor factory)
          Get a hash code, consistent with persistence "equality".
protected  Object getIdentifier(Object value, SessionImplementor session)
           
 String getIdentifierOrUniqueKeyPropertyName(Mapping factory)
          The name of the property on the associated entity to which our FK refers
 Type getIdentifierOrUniqueKeyType(Mapping factory)
          Determine the type of either (1) the identifier if we reference the associated entity's PK or (2) the unique key to which we refer (i.e.
 String getLHSPropertyName()
          Get the name of a property in the owning entity that provides the join key (null if the identifier)
 String getName()
          For entity types, the name correlates to the associated entity name.
 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)
          As part of 2-phase loading, when we perform resolving what is the resolved type for this type? Generally speaking the type and its semi-resolved type will be the same.
 boolean isAssociationType()
          An entity type is a type of association type
 boolean isEmbeddedInXML()
          
 boolean isEntityType()
          Explicitly, an entity type is an entity type ;)
 boolean isEqual(Object x, Object y, SessionFactoryImplementor factory)
          Compare two instances of the class mapped by this type for persistence "equality" (equality of persistent state).
 boolean isLogicalOneToOne()
          Is the association modeled here a 1-1 according to the logical moidel?
 boolean isMutable()
          Are objects of this type mutable.
protected  boolean isNotEmbedded(SessionImplementor session)
          Deprecated. To be removed in 5. Removed as part of removing the notion of DOM entity-mode. See Jira issue: HHH-7771
protected  boolean isNull(Object owner, SessionImplementor session)
           
protected abstract  boolean isNullable()
           
abstract  boolean isOneToOne()
          Is the association modeled here defined as a 1-1 in the database (physical model)?
 boolean isReferenceToPrimaryKey()
          Does this association foreign key reference the primary key of the other table? Otherwise, it references a property-ref.
 boolean isSame(Object x, Object y)
          Two entities are considered the same when their instances are the same.
 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)
          Extract a value of the mapped class from the JDBC result set.
 Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner)
          Extract a value of the mapped class from the JDBC result set.
 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 via a load.
protected  TypeFactory.TypeScope scope()
           
 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)
          Generate a loggable representation of an instance of the value mapped by this type.
 String toString()
          Generates a string representation of this type.
 
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, defaultSizes, dictatedSizes, 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

@Deprecated
protected EntityType(TypeFactory.TypeScope scope,
                                String entityName,
                                String uniqueKeyPropertyName,
                                boolean eager,
                                boolean isEmbeddedInXML,
                                boolean unwrapProxy)
Deprecated. Use EntityType(org.hibernate.type.TypeFactory.TypeScope, String, boolean, String, boolean, boolean) instead. See Jira issue: HHH-7771

Constructs the requested entity type mapping.

Parameters:
scope - The type scope
entityName - The name of the associated entity.
uniqueKeyPropertyName - The property-ref name, or null if we reference the PK of the associated entity.
eager - Is eager fetching enabled.
isEmbeddedInXML - Should values of this mapping be embedded in XML modes?
unwrapProxy - Is unwrapping of proxies allowed for this association; unwrapping says to return the "implementation target" of lazy prooxies; typically only possible with lazy="no-proxy".

EntityType

@Deprecated
protected EntityType(TypeFactory.TypeScope scope,
                                String entityName,
                                String uniqueKeyPropertyName,
                                boolean eager,
                                boolean unwrapProxy)
Deprecated. Use EntityType(org.hibernate.type.TypeFactory.TypeScope, String, boolean, String, boolean, boolean) instead.

Constructs the requested entity type mapping.

Parameters:
scope - The type scope
entityName - The name of the associated entity.
uniqueKeyPropertyName - The property-ref name, or null if we reference the PK of the associated entity.
eager - Is eager fetching enabled.
unwrapProxy - Is unwrapping of proxies allowed for this association; unwrapping says to return the "implementation target" of lazy prooxies; typically only possible with lazy="no-proxy".

EntityType

protected EntityType(TypeFactory.TypeScope scope,
                     String entityName,
                     boolean referenceToPrimaryKey,
                     String uniqueKeyPropertyName,
                     boolean eager,
                     boolean unwrapProxy)
Constructs the requested entity type mapping.

Parameters:
scope - The type scope
entityName - The name of the associated entity.
referenceToPrimaryKey - True if association references a primary key.
uniqueKeyPropertyName - The property-ref name, or null if we reference the PK of the associated entity.
eager - Is eager fetching enabled.
unwrapProxy - Is unwrapping of proxies allowed for this association; unwrapping says to return the "implementation target" of lazy prooxies; typically only possible with lazy="no-proxy".
Method Detail

scope

protected TypeFactory.TypeScope scope()

isAssociationType

public boolean isAssociationType()
An entity type is a type of association type

Specified by:
isAssociationType in interface Type
Overrides:
isAssociationType in class AbstractType
Returns:
True.

isEntityType

public final boolean isEntityType()
Explicitly, an entity type is an entity type ;)

Specified by:
isEntityType in interface Type
Overrides:
isEntityType in class AbstractType
Returns:
True.

isMutable

public boolean isMutable()
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

toString

public String toString()
Generates a string representation of this type.

Overrides:
toString in class Object
Returns:
string rep

getName

public String getName()
For entity types, the name correlates to the associated entity name.

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

isReferenceToPrimaryKey

public boolean isReferenceToPrimaryKey()
Does this association foreign key reference the primary key of the other table? Otherwise, it references a property-ref.

Returns:
True if this association reference the PK of the associated entity.

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

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

getPropertyName

public String getPropertyName()

getAssociatedEntityName

public final String getAssociatedEntityName()
The name of the associated entity.

Returns:
The associated entity name.

getAssociatedEntityName

public String getAssociatedEntityName(SessionFactoryImplementor factory)
The name of the associated entity.

Specified by:
getAssociatedEntityName in interface AssociationType
Parameters:
factory - The session factory, for resolution.
Returns:
The associated entity name.

getAssociatedJoinable

public Joinable getAssociatedJoinable(SessionFactoryImplementor factory)
                               throws MappingException
Retrieves the Joinable defining the associated entity.

Specified by:
getAssociatedJoinable in interface AssociationType
Parameters:
factory - The session factory.
Returns:
The associated joinable
Throws:
MappingException - Generally indicates an invalid entity name.

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.

The problem here is that we do not necessarily have a ref to the associated entity persister (nor to the session factory, to look it up) which is really needed to "do the right thing" here...

Specified by:
getReturnedClass in interface Type
Returns:
The entiyt class.

nullSafeGet

public Object nullSafeGet(ResultSet rs,
                          String name,
                          SessionImplementor session,
                          Object owner)
                   throws HibernateException,
                          SQLException
Extract a value of the mapped class from the JDBC result set. Implementors should handle possibility of null values. This form might be called if the type is known to be a single-column type.

Specified by:
nullSafeGet in interface Type
Parameters:
rs - The result set from which to extract value.
name - the column name making up this type value (use to read from result set)
session - The originating session
owner - the parent entity
Returns:
The extracted value
Throws:
HibernateException - An error from Hibernate
SQLException - An error from the JDBC driver

nullSafeGet

public final Object nullSafeGet(ResultSet rs,
                                String[] names,
                                SessionImplementor session,
                                Object owner)
                         throws HibernateException,
                                SQLException
Extract a value of the mapped class from the JDBC result set. Implementors should handle possibility of null values.

Specified by:
nullSafeGet in interface Type
Parameters:
rs - The result set from which to extract value.
names - the column names making up this type value (use to read from result set)
session - The originating session
owner - the parent entity
Returns:
The extracted value
Throws:
HibernateException - An error from Hibernate
SQLException - An error from the JDBC driver
See Also:
alternative, 2-phase property initialization

isSame

public final boolean isSame(Object x,
                            Object y)
Two entities are considered the same when their instances are the same.

Specified by:
isSame in interface Type
Overrides:
isSame in class AbstractType
Parameters:
x - One entity instance
y - Another entity instance
Returns:
True if x == y; false otherwise.

compare

public int compare(Object x,
                   Object y)
Perform a Comparator style comparison between values

Specified by:
compare in interface Type
Overrides:
compare in class AbstractType
Parameters:
x - The first value
y - The second value
Returns:
The comparison result. See Comparator.compare(T, T) for a discussion.

deepCopy

public Object deepCopy(Object value,
                       SessionFactoryImplementor factory)
Return a deep copy of the persistent state, stopping at entities and at collections.

Specified by:
deepCopy in interface Type
Parameters:
value - The value to be copied
factory - The session factory
Returns:
The deep copy

replace

public Object replace(Object original,
                      Object target,
                      SessionImplementor session,
                      Object owner,
                      Map copyCache)
               throws HibernateException
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
session - The originating session
owner - The owner of the value
copyCache - The cache of already copied/replaced values
Returns:
the value to be merged
Throws:
HibernateException - An error from Hibernate

getHashCode

public int getHashCode(Object x,
                       SessionFactoryImplementor factory)
Get a hash code, consistent with persistence "equality". Again for most types the normal usage is to delegate to the value's hashCode.

Specified by:
getHashCode in interface Type
Overrides:
getHashCode in class AbstractType
Parameters:
x - The value for which to retrieve a hash code
factory - The session factory
Returns:
The hash code

isEqual

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

This should always equate to some form of comparison of the value's internal state. As an example, for something like a date the comparison should be based on its internal "time" state based on the specific portion it is meant to represent (timestamp, date, time).

Specified by:
isEqual in interface Type
Overrides:
isEqual in class AbstractType
Parameters:
x - The first value
y - The second value
factory - The session factory
Returns:
True if there are considered equal (see discussion above).

isEmbeddedInXML

public boolean isEmbeddedInXML()

Specified by:
isEmbeddedInXML in interface AssociationType

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
Parse the XML representation of an instance.

Specified by:
fromXMLNode in interface Type
Parameters:
xml - The XML node from which to read the value
factory - The session factory
Returns:
an instance of the mapped class
Throws:
HibernateException - An error from Hibernate

setToXMLNode

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

Specified by:
setToXMLNode in interface Type
Parameters:
node - The XML node to which to write the value
value - The value to write
factory - The session factory
Throws:
HibernateException - An error from Hibernate

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

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
Parameters:
value - an identifier or value returned by hydrate()
session - the session
owner - the parent entity
Returns:
the given value, or the value associated with the identifier
Throws:
HibernateException - An error from Hibernate
See Also:
Type.hydrate(java.sql.ResultSet, java.lang.String[], org.hibernate.engine.spi.SessionImplementor, java.lang.Object)

getSemiResolvedType

public Type getSemiResolvedType(SessionFactoryImplementor factory)
Description copied from interface: Type
As part of 2-phase loading, when we perform resolving what is the resolved type for this type? Generally speaking the type and its semi-resolved type will be the same. The main deviation from this is in the case of an entity where the type would be the entity type and semi-resolved type would be its identifier type

Specified by:
getSemiResolvedType in interface Type
Overrides:
getSemiResolvedType in class AbstractType
Parameters:
factory - The session factory
Returns:
The semi-resolved type

getAssociatedEntityPersister

protected EntityPersister getAssociatedEntityPersister(SessionFactoryImplementor factory)

getIdentifier

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

isNotEmbedded

@Deprecated
protected boolean isNotEmbedded(SessionImplementor session)
Deprecated. To be removed in 5. Removed as part of removing the notion of DOM entity-mode. See Jira issue: HHH-7771


toLoggableString

public String toLoggableString(Object value,
                               SessionFactoryImplementor factory)
Generate a loggable representation of an instance of the value mapped by this type.

Specified by:
toLoggableString in interface Type
Parameters:
value - The instance to be logged.
factory - The session factory.
Returns:
The loggable string.
Throws:
HibernateException - Generally some form of resolution problem.

isOneToOne

public abstract boolean isOneToOne()
Is the association modeled here defined as a 1-1 in the database (physical model)?

Returns:
True if a 1-1 in the database; false otherwise.

isLogicalOneToOne

public boolean isLogicalOneToOne()
Is the association modeled here a 1-1 according to the logical moidel?

Returns:
True if a 1-1 in the logical model; false otherwise.

getIdentifierOrUniqueKeyType

public final Type getIdentifierOrUniqueKeyType(Mapping factory)
                                        throws MappingException
Determine the type of either (1) the identifier if we reference the associated entity's PK or (2) the unique key to which we refer (i.e. the property-ref).

Parameters:
factory - The mappings...
Returns:
The appropriate type.
Throws:
MappingException - Generally, if unable to resolve the associated entity name or unique key property name.

getIdentifierOrUniqueKeyPropertyName

public final String getIdentifierOrUniqueKeyPropertyName(Mapping factory)
                                                  throws MappingException
The name of the property on the associated entity to which our FK refers

Parameters:
factory - The mappings...
Returns:
The appropriate property name.
Throws:
MappingException - Generally, if unable to resolve the associated entity name

isNullable

protected abstract boolean isNullable()

resolveIdentifier

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

Parameters:
id - The entity id to resolve
session - The orginating session.
Returns:
The resolved identifier (i.e., loaded entity).
Throws:
HibernateException - Indicates problems performing the load.

isNull

protected boolean isNull(Object owner,
                         SessionImplementor session)

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.

Parameters:
entityName - The name of the entity to load
uniqueKeyPropertyName - The name of the property defining the uniqie key.
key - The unique key property value.
session - The originating session.
Returns:
The loaded entity
Throws:
HibernateException - generally indicates problems performing the load.


Copyright © 2001-2015 Red Hat, Inc. All Rights Reserved.