public abstract class

EntityType

extends AbstractType
implements AssociationType
java.lang.Object
   ↳ org.hibernate.type.AbstractType
     ↳ org.hibernate.type.EntityType
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Base for types which map associations to persistent entities.

Summary

Fields
protected final boolean isEmbeddedInXML
protected final String uniqueKeyPropertyName
Protected Constructors
EntityType(TypeFactory.TypeScope scope, String entityName, String uniqueKeyPropertyName, boolean eager, boolean isEmbeddedInXML, boolean unwrapProxy)
Constructs the requested entity type mapping.
Public Methods
int compare(Object x, Object y, EntityMode entityMode)
Perform a Comparator style comparison between values
Object deepCopy(Object value, EntityMode entityMode, SessionFactoryImplementor factory)
Return a deep copy of the persistent state, stopping at entities and at collections.
Object fromXMLNode(Node xml, Mapping factory)
Parse the XML representation of an instance.
final String getAssociatedEntityName()
The name of the associated entity.
String getAssociatedEntityName(SessionFactoryImplementor factory)
The name of the associated entity.
Joinable getAssociatedJoinable(SessionFactoryImplementor factory)
Retrieves the Joinable defining the associated entity.
int getHashCode(Object x, EntityMode entityMode, SessionFactoryImplementor factory)
Get a hash code, consistent with persistence "equality".
final String getIdentifierOrUniqueKeyPropertyName(Mapping factory)
The name of the property on the associated entity to which our FK refers
final 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()
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)
final Class getReturnedClass()
This returns the wrong class for an entity with a proxy, or for a named entity.
Type getSemiResolvedType(SessionFactoryImplementor factory)
Get the type of a semi-resolved value.
boolean isAssociationType()
An entity type is a type of association type
boolean isEmbeddedInXML()
final boolean isEntityType()
Explicitly, an entity type is 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 isLogicalOneToOne()
Is the association modeled here a 1-1 according to the logical moidel?
boolean isMutable()
Are objects of this type mutable.
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.
final boolean isSame(Object x, Object y, EntityMode entityMode)
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 name, SessionImplementor session, Object owner)
Retrieve an instance of the mapped class from a JDBC resultset.
final Object nullSafeGet(ResultSet rs, String[] names, 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
void setToXMLNode(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.
Protected Methods
final Object getIdentifier(Object value, SessionImplementor session)
boolean isNotEmbedded(SessionImplementor session)
boolean isNull(Object owner, SessionImplementor session)
abstract boolean isNullable()
final Object resolveIdentifier(Serializable id, SessionImplementor session)
Resolve an identifier via a load.
TypeFactory.TypeScope scope()
[Expand]
Inherited Methods
From class org.hibernate.type.AbstractType
From class java.lang.Object
From interface org.hibernate.type.AssociationType
From interface org.hibernate.type.Type

Fields

protected final boolean isEmbeddedInXML

protected final String uniqueKeyPropertyName

Protected Constructors

protected EntityType (TypeFactory.TypeScope scope, String entityName, String uniqueKeyPropertyName, boolean eager, boolean isEmbeddedInXML, boolean unwrapProxy)

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".

Public Methods

public int compare (Object x, Object y, EntityMode entityMode)

Perform a Comparator style comparison between values

Parameters
x The first value
y The second value
entityMode The entity mode of the values.
Returns

public Object deepCopy (Object value, EntityMode entityMode, SessionFactoryImplementor factory)

Return a deep copy of the persistent state, stopping at entities and at collections.

Parameters
value generally a collection element or entity field
Returns
  • Object a copy

public Object fromXMLNode (Node xml, Mapping factory)

Parse the XML representation of an instance.

Returns
  • an instance of the type

public final String getAssociatedEntityName ()

The name of the associated entity.

Returns
  • The associated entity name.

public String getAssociatedEntityName (SessionFactoryImplementor factory)

The name of the associated entity.

Parameters
factory The session factory, for resolution.
Returns
  • The associated entity name.

public Joinable getAssociatedJoinable (SessionFactoryImplementor factory)

Retrieves the Joinable defining the associated entity.

Parameters
factory The session factory.
Returns
  • The associated joinable
Throws
MappingException Generally indicates an invalid entity name.

public int getHashCode (Object x, EntityMode entityMode, 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.

Parameters
x The value for which to retrieve a hash code
entityMode The entity mode of the value.
factory The session factory
Returns
  • The hash code

public final String getIdentifierOrUniqueKeyPropertyName (Mapping factory)

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

public final 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. 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.

public String getLHSPropertyName ()

Get the name of a property in the owning entity that provides the join key (null if the identifier)

public String getName ()

For entity types, the name correlates to the associated entity name.

Returns
  • String the Hibernate type name

public 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

public String getPropertyName ()

public 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)

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...

Returns
  • The entiyt class.

public Type getSemiResolvedType (SessionFactoryImplementor factory)

Get the type of a semi-resolved value.

public boolean isAssociationType ()

An entity type is a type of association type

Returns
  • True.

public boolean isEmbeddedInXML ()

public final boolean isEntityType ()

Explicitly, an entity type is an entity type ;)

Returns
  • True.

public 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).

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).

Parameters
x The first value
y The second value
entityMode The entity mode of the values.
factory The session factory
Returns
  • True if there are considered equal (see discussion above).

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.

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.)

Returns
  • boolean

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.

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.

public final boolean isSame (Object x, Object y, EntityMode entityMode)

Two entities are considered the same when their instances are the same.

Parameters
x One entity instance
y Another entity instance
entityMode The entity mode.
Returns
  • True if x == y; false otherwise.

public boolean isXMLElement ()

public Object loadByUniqueKey (String entityName, String uniqueKeyPropertyName, Object key, SessionImplementor session)

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.

public Object nullSafeGet (ResultSet rs, String name, SessionImplementor session, Object owner)

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.

Parameters
name the column name
owner the parent entity
Returns
  • Object

public final Object nullSafeGet (ResultSet rs, String[] names, SessionImplementor session, Object owner)

Retrieve an instance of the mapped class from a JDBC resultset. Implementors should handle possibility of null values.

Parameters
names the column names
owner the parent entity
Returns
  • Object

public 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. 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.

Parameters
original the value from the detached entity being merged
target the value in the managed entity
Returns
  • the value to be merged

public Object resolve (Object value, SessionImplementor session, Object owner)

Resolve an identifier or unique key value

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

public void setToXMLNode (Node node, Object value, SessionFactoryImplementor factory)

A representation of the value to be embedded in an XML element.

Returns
  • String

public String toLoggableString (Object value, SessionFactoryImplementor factory)

Generate a loggable representation of an instance of the value mapped by this type.

Parameters
value The instance to be logged.
factory The session factory.
Returns
  • The loggable string.
Throws
HibernateException Generally some form of resolution problem.

public String toString ()

Generates a string representation of this type.

Returns
  • string rep

Protected Methods

protected final Object getIdentifier (Object value, SessionImplementor session)

protected boolean isNotEmbedded (SessionImplementor session)

protected boolean isNull (Object owner, SessionImplementor session)

protected abstract boolean isNullable ()

protected final Object resolveIdentifier (Serializable id, SessionImplementor session)

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.

protected TypeFactory.TypeScope scope ()