Package org.hibernate.type
Class EntityType
- java.lang.Object
-
- org.hibernate.type.AbstractType
-
- 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
Fields Modifier and Type Field Description protected 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, String superTypeEntityName)
protected
EntityType(TypeConfiguration typeConfiguration, String entityName, boolean referenceToPrimaryKey, String uniqueKeyPropertyName, boolean eager, boolean unwrapProxy)
Constructs the requested entity type mapping.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
compare(Object x, Object y)
Perform aComparator
-style comparison of the given values.int
compare(Object x, Object y, SessionFactoryImplementor factory)
Object
deepCopy(Object value, SessionFactoryImplementor factory)
Return a deep copy of the persistent state, stopping at entities and at collections.String
getAssociatedEntityName()
The name of the associated entity.String
getAssociatedEntityName(SessionFactoryImplementor factory)
The name of the associated entity.EntityPersister
getAssociatedEntityPersister(SessionFactoryImplementor factory)
Joinable
getAssociatedJoinable(SessionFactoryImplementor factory)
Retrieves theJoinable
defining the associated entity.int
getHashCode(Object x, SessionFactoryImplementor factory)
Get a hash code, consistent with persistence "equality".protected Object
getIdentifier(Object value, SessionFactoryImplementor sessionFactory)
protected Object
getIdentifier(Object value, SharedSessionContractImplementor session)
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.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
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)boolean
isAssociationType()
An entity type is a type of association typeboolean
isEager(Boolean overridingEager)
Would an entity be eagerly loaded given the value provided foroverridingEager
?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", that is, equality of persistent state.boolean
isLogicalOneToOne()
Is the association modeled here a 1-1 according to the logical model?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.protected boolean
isNull(Object owner, SharedSessionContractImplementor session)
abstract boolean
isNullable()
The nullability of the property.abstract boolean
isOneToOne()
Is the association modeled here defined as a 1-1 in the database (physical model)?boolean
isReferenceToIdentifierProperty()
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.Object
loadByUniqueKey(String entityName, String uniqueKeyPropertyName, Object key, SharedSessionContractImplementor session)
Load an instance by a unique key that is not the primary key.void
nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, SharedSessionContractImplementor session)
Bind a value represented by an instance of themapped class
to the given JDBCPreparedStatement
, ignoring some columns as dictated by thesettable
parameter.void
nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
Bind a value represented by an instance of themapped class
to the given JDBCPreparedStatement
, ignoring some columns as dictated by thesettable
parameter.Object
replace(Object original, Object target, SharedSessionContractImplementor session, Object owner, Map<Object,Object> 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)
protected Object
resolve(Object value, SharedSessionContractImplementor session, Object owner)
Resolve an identifier or unique key valueprotected Object
resolveIdentifier(Object id, SharedSessionContractImplementor session)
protected Object
resolveIdentifier(Object id, SharedSessionContractImplementor session, Boolean overridingEager)
Resolve an identifier via a load.protected TypeConfiguration
scope()
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, disassemble, getHashCode, isAnyType, isCollectionType, isComponentType, isDirty, isEqual, isModified, replace
-
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, disassemble, getColumnSpan, getHashCode, getSqlTypeCodes, isAnyType, isCollectionType, isComponentType, isDirty, isDirty, isEqual, isModified, replace, toColumnNullness
-
-
-
-
Field Detail
-
uniqueKeyPropertyName
protected final String uniqueKeyPropertyName
-
-
Constructor Detail
-
EntityType
protected EntityType(TypeConfiguration typeConfiguration, String entityName, boolean referenceToPrimaryKey, String uniqueKeyPropertyName, boolean eager, boolean unwrapProxy)
Constructs the requested entity type mapping.
-
EntityType
protected EntityType(EntityType original, String superTypeEntityName)
-
-
Method Detail
-
scope
protected TypeConfiguration 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 String toString()
Generates a string representation of this type.
-
getName
public 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 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 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 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 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 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 entity class.
-
nullSafeSet
public void nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, SharedSessionContractImplementor session) throws SQLException
Description copied from interface:Type
Bind a value represented by an instance of themapped class
to the given JDBCPreparedStatement
, ignoring some columns as dictated by thesettable
parameter. Implementors should handle the possibility of null values. A multi-column type should bind parameters starting fromindex
.- 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:
SQLException
- An error from the JDBC driver
-
nullSafeSet
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws SQLException
Description copied from interface:Type
Bind a value represented by an instance of themapped class
to the given JDBCPreparedStatement
, ignoring some columns as dictated by thesettable
parameter. Implementors should handle the possibility of null values. A multi-column type should bind parameters starting fromindex
.- 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:
SQLException
- An error from the JDBC driver
-
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 interfaceType
- Overrides:
isSame
in classAbstractType
- Parameters:
x
- One entity instancey
- Another entity instance- Returns:
- True if x == y; false otherwise.
-
compare
public int compare(Object x, Object y)
Description copied from interface:Type
Perform aComparator
-style comparison of the given values.- Specified by:
compare
in interfaceType
- Overrides:
compare
in classAbstractType
- Parameters:
x
- The first valuey
- The second value- Returns:
- The comparison result.
- See Also:
Comparator.compare(Object, Object)
-
compare
public int compare(Object x, Object y, SessionFactoryImplementor factory)
-
deepCopy
public Object deepCopy(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 Object replace(Object original, Object target, SharedSessionContractImplementor session, Object owner, Map<Object,Object> 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(Object x, SessionFactoryImplementor factory)
Description copied from interface:Type
Get a hash code, consistent with persistence "equality". For most types this could simply delegate toType.getHashCode(Object)
.- 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(Object x, Object y, SessionFactoryImplementor factory)
Description copied from interface:Type
Compare two instances of the class mapped by this type for persistence "equality", that is, equality of persistent state. For most types this could simply delegate toType.isEqual(Object, Object)
.This should always equate to some form of comparison of the value's internal state. As an example, for Java's
Date
class, the comparison should be of its internal state, but based only on the specific part which is persistent (the timestamp, date, or 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).
-
resolve
protected Object resolve(Object value, SharedSessionContractImplementor session, Object owner)
Resolve an identifier or unique key value
-
isEager
public boolean isEager(Boolean overridingEager)
Would an entity be eagerly loaded given the value provided foroverridingEager
?- Parameters:
overridingEager
- can override eager from the mapping.- Returns:
- If
overridingEager
is null, then it does not override. If true or false then it overrides the mapping value.
-
getAssociatedEntityPersister
public EntityPersister getAssociatedEntityPersister(SessionFactoryImplementor factory)
-
getIdentifier
protected final Object getIdentifier(Object value, SharedSessionContractImplementor session) throws HibernateException
- Throws:
HibernateException
-
getIdentifier
protected final Object getIdentifier(Object value, SessionFactoryImplementor sessionFactory) throws HibernateException
- Throws:
HibernateException
-
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 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 model?- 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
-
isReferenceToIdentifierProperty
public boolean isReferenceToIdentifierProperty()
-
isNullable
public abstract boolean isNullable()
The nullability of the property.- Returns:
- The nullability of the property.
-
resolveIdentifier
protected final Object resolveIdentifier(Object id, SharedSessionContractImplementor session, Boolean overridingEager) throws HibernateException
Resolve an identifier via a load.- Parameters:
id
- The entity id to resolvesession
- The originating session.- Returns:
- The resolved identifier (i.e., loaded entity).
- Throws:
HibernateException
- Indicates problems performing the load.
-
resolveIdentifier
protected final Object resolveIdentifier(Object id, SharedSessionContractImplementor session) throws HibernateException
- Throws:
HibernateException
-
isNull
protected boolean isNull(Object owner, SharedSessionContractImplementor session)
-
loadByUniqueKey
public Object loadByUniqueKey(String entityName, String uniqueKeyPropertyName, 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 unique key.key
- The unique key property value.session
- The originating session.- Returns:
- The loaded entity
- Throws:
HibernateException
- generally indicates problems performing the load.
-
-