Package org.hibernate.type
Class EntityType
- java.lang.Object
-
- org.hibernate.type.AbstractType
-
- org.hibernate.type.EntityType
-
- All Implemented Interfaces:
java.io.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
Fields Modifier and Type Field Description protected java.lang.String
uniqueKeyPropertyName
-
Fields inherited from class org.hibernate.type.AbstractType
LEGACY_DEFAULT_SIZE, LEGACY_DICTATED_SIZE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
EntityType(EntityType original, java.lang.String superTypeEntityName)
protected
EntityType(TypeFactory.TypeScope scope, java.lang.String entityName, boolean referenceToPrimaryKey, java.lang.String uniqueKeyPropertyName, boolean eager, boolean unwrapProxy)
Constructs the requested entity type mapping.protected
EntityType(TypeFactory.TypeScope scope, java.lang.String entityName, java.lang.String uniqueKeyPropertyName, boolean eager, boolean unwrapProxy)
Deprecated.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
compare(java.lang.Object x, java.lang.Object y)
Perform aComparator
style comparison between valuesjava.lang.Object
deepCopy(java.lang.Object value, SessionFactoryImplementor factory)
Return a deep copy of the persistent state, stopping at entities and at collections.java.lang.String
getAssociatedEntityName()
The name of the associated entity.java.lang.String
getAssociatedEntityName(SessionFactoryImplementor factory)
The name of the associated entity.protected EntityPersister
getAssociatedEntityPersister(SessionFactoryImplementor factory)
Joinable
getAssociatedJoinable(SessionFactoryImplementor factory)
Retrieves theJoinable
defining the associated entity.int
getHashCode(java.lang.Object x, SessionFactoryImplementor factory)
Get a hash code, consistent with persistence "equality".protected java.lang.Object
getIdentifier(java.lang.Object value, SharedSessionContractImplementor session)
java.lang.String
getIdentifierOrUniqueKeyPropertyName(Mapping factory)
The name of the property on the associated entity to which our FK refersType
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.java.lang.String
getLHSPropertyName()
Get the name of a property in the owning entity that provides the join key (null if the identifier)java.lang.String
getName()
For entity types, the name correlates to the associated entity name.java.lang.String
getOnCondition(java.lang.String alias, SessionFactoryImplementor factory, java.util.Map enabledFilters)
Get the "filtering" SQL fragment that is applied in the SQL on clause, in addition to the usual join conditionjava.lang.String
getOnCondition(java.lang.String alias, SessionFactoryImplementor factory, java.util.Map enabledFilters, java.util.Set<java.lang.String> treatAsDeclarations)
Get the "filtering" SQL fragment that is applied in the SQL on clause, in addition to the usual join conditionjava.lang.String
getPropertyName()
java.lang.Class
getReturnedClass()
This returns the wrong class for an entity with a proxy, or for a named entity.java.lang.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 typeboolean
isEntityType()
Explicitly, an entity type is an entity type ;)boolean
isEqual(java.lang.Object x, java.lang.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
isNull(java.lang.Object owner, SharedSessionContractImplementor session)
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(java.lang.Object x, java.lang.Object y)
Two entities are considered the same when their instances are the same.java.lang.Object
loadByUniqueKey(java.lang.String entityName, java.lang.String uniqueKeyPropertyName, java.lang.Object key, SharedSessionContractImplementor session)
Load an instance by a unique key that is not the primary key.java.lang.Object
nullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, SharedSessionContractImplementor session, java.lang.Object owner)
Extract a value of themapped class
from the JDBC result set.java.lang.Object
nullSafeGet(java.sql.ResultSet rs, java.lang.String name, SharedSessionContractImplementor session, java.lang.Object owner)
Extract a value of themapped class
from the JDBC result set.void
nullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, boolean[] settable, SharedSessionContractImplementor session)
Bind a value represented by an instance of themapped class
to the JDBC prepared statement, ignoring some columns as dictated by the 'settable' parameter.void
nullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, SharedSessionContractImplementor session)
Bind a value represented by an instance of themapped class
to the JDBC prepared statement.java.lang.Object
replace(java.lang.Object original, java.lang.Object target, SharedSessionContractImplementor session, java.lang.Object owner, java.util.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.protected Type
requireIdentifierOrUniqueKeyType(Mapping mapping)
java.lang.Object
resolve(java.lang.Object value, SharedSessionContractImplementor session, java.lang.Object owner)
Resolve an identifier or unique key valuejava.lang.Object
resolve(java.lang.Object value, SharedSessionContractImplementor session, java.lang.Object owner, java.lang.Boolean overridingEager)
The second phase of 2-phase loading.protected java.lang.Object
resolveIdentifier(java.io.Serializable id, SharedSessionContractImplementor session)
protected java.lang.Object
resolveIdentifier(java.io.Serializable id, SharedSessionContractImplementor session, java.lang.Boolean overridingEager)
Resolve an identifier via a load.protected TypeFactory.TypeScope
scope()
java.lang.String
toLoggableString(java.lang.Object value, SessionFactoryImplementor factory)
Generate a loggable representation of an instance of the value mapped by this type.java.lang.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, 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, replace, semiResolve, sqlTypes, toColumnNullness
-
-
-
-
Constructor Detail
-
EntityType
@Deprecated protected EntityType(TypeFactory.TypeScope scope, java.lang.String entityName, java.lang.String uniqueKeyPropertyName, boolean eager, boolean unwrapProxy)
Deprecated.Constructs the requested entity type mapping.- Parameters:
scope
- The type scopeentityName
- 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, java.lang.String entityName, boolean referenceToPrimaryKey, java.lang.String uniqueKeyPropertyName, boolean eager, boolean unwrapProxy)
Constructs the requested entity type mapping.- Parameters:
scope
- The type scopeentityName
- 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".
-
EntityType
protected EntityType(EntityType original, java.lang.String superTypeEntityName)
-
-
Method Detail
-
scope
protected TypeFactory.TypeScope scope()
-
isAssociationType
public boolean isAssociationType()
An entity type is a type of association type- Specified by:
isAssociationType
in interfaceType
- Overrides:
isAssociationType
in classAbstractType
- Returns:
- True.
-
isEntityType
public final boolean isEntityType()
Explicitly, an entity type is an entity type ;)- Specified by:
isEntityType
in interfaceType
- Overrides:
isEntityType
in classAbstractType
- Returns:
- True.
-
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.)
-
toString
public java.lang.String toString()
Generates a string representation of this type.- Overrides:
toString
in classjava.lang.Object
- Returns:
- string rep
-
getName
public java.lang.String getName()
For entity types, the name correlates to the associated entity 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 java.lang.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 interfaceAssociationType
-
getLHSPropertyName
public java.lang.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 interfaceAssociationType
-
getPropertyName
public java.lang.String getPropertyName()
-
getAssociatedEntityName
public final java.lang.String getAssociatedEntityName()
The name of the associated entity.- Returns:
- The associated entity name.
-
getAssociatedEntityName
public java.lang.String getAssociatedEntityName(SessionFactoryImplementor factory)
The name of the associated entity.- Specified by:
getAssociatedEntityName
in interfaceAssociationType
- Parameters:
factory
- The session factory, for resolution.- Returns:
- The associated entity name.
-
getAssociatedJoinable
public Joinable getAssociatedJoinable(SessionFactoryImplementor factory) throws MappingException
Retrieves theJoinable
defining the associated entity.- Specified by:
getAssociatedJoinable
in interfaceAssociationType
- Parameters:
factory
- The session factory.- Returns:
- The associated joinable
- Throws:
MappingException
- Generally indicates an invalid entity name.
-
getReturnedClass
public final java.lang.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 interfaceType
- Returns:
- The entiyt class.
-
nullSafeGet
public java.lang.Object nullSafeGet(java.sql.ResultSet rs, java.lang.String name, SharedSessionContractImplementor session, java.lang.Object owner) throws HibernateException, java.sql.SQLException
Description copied from interface:Type
Extract a value of themapped 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 interfaceType
- 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 sessionowner
- the parent entity- Returns:
- The extracted value
- Throws:
HibernateException
- An error from Hibernatejava.sql.SQLException
- An error from the JDBC driver
-
nullSafeGet
public final java.lang.Object nullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, SharedSessionContractImplementor session, java.lang.Object owner) throws HibernateException, java.sql.SQLException
Description copied from interface:Type
Extract a value of themapped class
from the JDBC result set. Implementors should handle possibility of null values.- Specified by:
nullSafeGet
in interfaceType
- 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 sessionowner
- the parent entity- Returns:
- The extracted value
- Throws:
HibernateException
- An error from Hibernatejava.sql.SQLException
- An error from the JDBC driver- See Also:
alternative, 2-phase property initialization
-
nullSafeSet
public void nullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, boolean[] settable, SharedSessionContractImplementor session) throws java.sql.SQLException
Description copied from interface:Type
Bind a value represented by an instance of themapped class
to the JDBC prepared statement, ignoring some columns as dictated by the 'settable' parameter. Implementors should handle the possibility of null values. A multi-column type should bind parameters starting from index.- Specified by:
nullSafeSet
in interfaceType
- Parameters:
st
- The JDBC prepared statement to which to bindvalue
- the object to writeindex
- starting parameter bind indexsettable
- an array indicating which columns to bind/ignoresession
- The originating session- Throws:
java.sql.SQLException
- An error from the JDBC driver
-
nullSafeSet
public void nullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, SharedSessionContractImplementor session) throws java.sql.SQLException
Description copied from interface:Type
Bind a value represented by an instance of themapped class
to the JDBC prepared statement. Implementors should handle possibility of null values. A multi-column type should bind parameters starting from index.- Specified by:
nullSafeSet
in interfaceType
- Parameters:
st
- The JDBC prepared statement to which to bindvalue
- the object to writeindex
- starting parameter bind indexsession
- The originating session- Throws:
java.sql.SQLException
- An error from the JDBC driver
-
isSame
public final boolean isSame(java.lang.Object x, java.lang.Object y)
Two entities are considered the same when their instances are the same.- Specified by:
isSame
in interfaceType
- Overrides:
isSame
in classAbstractType
- Parameters:
x
- One entity instancey
- Another entity instance- Returns:
- True if x == y; false otherwise.
-
compare
public int compare(java.lang.Object x, java.lang.Object y)
Description copied from interface:Type
Perform aComparator
style comparison between values- Specified by:
compare
in interfaceType
- Overrides:
compare
in classAbstractType
- Parameters:
x
- The first valuey
- The second value- Returns:
- The comparison result. See
Comparator.compare(T, T)
for a discussion.
-
deepCopy
public java.lang.Object deepCopy(java.lang.Object value, SessionFactoryImplementor factory)
Description copied from interface:Type
Return a deep copy of the persistent state, stopping at entities and at collections.
-
replace
public java.lang.Object replace(java.lang.Object original, java.lang.Object target, SharedSessionContractImplementor session, java.lang.Object owner, java.util.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 interfaceType
- Parameters:
original
- the value from the detached entity being mergedtarget
- the value in the managed entitysession
- The originating sessionowner
- The owner of the valuecopyCache
- The cache of already copied/replaced values- Returns:
- the value to be merged
- Throws:
HibernateException
- An error from Hibernate
-
getHashCode
public int getHashCode(java.lang.Object x, SessionFactoryImplementor factory)
Description copied from interface:Type
Get a hash code, consistent with persistence "equality". Again for most types the normal usage is to delegate to the value'shashCode
.- Specified by:
getHashCode
in interfaceType
- Overrides:
getHashCode
in classAbstractType
- Parameters:
x
- The value for which to retrieve a hash codefactory
- The session factory- Returns:
- The hash code
-
isEqual
public boolean isEqual(java.lang.Object x, java.lang.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 interfaceType
- Overrides:
isEqual
in classAbstractType
- Parameters:
x
- The first valuey
- The second valuefactory
- The session factory- Returns:
- True if there are considered equal (see discussion above).
-
getOnCondition
public java.lang.String getOnCondition(java.lang.String alias, SessionFactoryImplementor factory, java.util.Map enabledFilters)
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 interfaceAssociationType
-
getOnCondition
public java.lang.String getOnCondition(java.lang.String alias, SessionFactoryImplementor factory, java.util.Map enabledFilters, java.util.Set<java.lang.String> treatAsDeclarations)
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 interfaceAssociationType
-
resolve
public java.lang.Object resolve(java.lang.Object value, SharedSessionContractImplementor session, java.lang.Object owner) throws HibernateException
Resolve an identifier or unique key value- Specified by:
resolve
in interfaceType
- Overrides:
resolve
in classAbstractType
- Throws:
HibernateException
- See Also:
Type.resolve(Object, SharedSessionContractImplementor, Object, Boolean)
-
resolve
public java.lang.Object resolve(java.lang.Object value, SharedSessionContractImplementor session, java.lang.Object owner, java.lang.Boolean overridingEager) throws HibernateException
Description copied from interface:Type
The second phase of 2-phase loading. Only really pertinent for entities and collections. Here we resolve the identifier to an entity or collection instance- Specified by:
resolve
in interfaceType
- Parameters:
value
- an identifier or value returned by hydrate()session
- the sessionowner
- the parent entityoverridingEager
- can override eager from the mapping. For example because ofLoadQueryInfluencers
If null, then it does not override. If true or false then it overrides the mapping value.- 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.SharedSessionContractImplementor, 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 interfaceType
- Overrides:
getSemiResolvedType
in classAbstractType
- Parameters:
factory
- The session factory- Returns:
- The semi-resolved type
-
getAssociatedEntityPersister
protected EntityPersister getAssociatedEntityPersister(SessionFactoryImplementor factory)
-
getIdentifier
protected final java.lang.Object getIdentifier(java.lang.Object value, SharedSessionContractImplementor session) throws HibernateException
- Throws:
HibernateException
-
toLoggableString
public java.lang.String toLoggableString(java.lang.Object value, SessionFactoryImplementor factory)
Generate a loggable representation of an instance of the value mapped by this type.- Specified by:
toLoggableString
in interfaceType
- 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 java.lang.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
public abstract boolean isNullable()
-
resolveIdentifier
protected final java.lang.Object resolveIdentifier(java.io.Serializable id, SharedSessionContractImplementor session, java.lang.Boolean overridingEager) throws HibernateException
Resolve an identifier via a load.- Parameters:
id
- The entity id to resolvesession
- The orginating session.- Returns:
- The resolved identifier (i.e., loaded entity).
- Throws:
HibernateException
- Indicates problems performing the load.
-
resolveIdentifier
protected final java.lang.Object resolveIdentifier(java.io.Serializable id, SharedSessionContractImplementor session) throws HibernateException
- Throws:
HibernateException
-
isNull
protected boolean isNull(java.lang.Object owner, SharedSessionContractImplementor session)
-
loadByUniqueKey
public java.lang.Object loadByUniqueKey(java.lang.String entityName, java.lang.String uniqueKeyPropertyName, java.lang.Object key, SharedSessionContractImplementor session) throws HibernateException
Load an instance by a unique key that is not the primary key.- Parameters:
entityName
- The name of the entity to loaduniqueKeyPropertyName
- 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.
-
-