Class EntityType

    • 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

      • 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()
        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
      • 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:
        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.
      • 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 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 the mapped class to the given JDBC PreparedStatement, 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 interface Type
        Parameters:
        st - The JDBC prepared statement to which to bind
        value - the object to write
        index - starting parameter bind index
        settable - an array indicating which columns to bind/ignore
        session - 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 the mapped class to the given JDBC PreparedStatement, 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 interface Type
        Parameters:
        st - The JDBC prepared statement to which to bind
        value - the object to write
        index - starting parameter bind index
        session - 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 interface Type
        Overrides:
        isSame in class AbstractType
        Parameters:
        x - One entity instance
        y - Another entity instance
        Returns:
        True if x == y; false otherwise.
      • 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.
        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,
                              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 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
      • 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 to Type.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 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).
      • isEager

        public boolean isEager​(Boolean overridingEager)
        Would an entity be eagerly loaded given the value provided for overridingEager?
        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.
      • 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 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.
      • 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 load
        uniqueKeyPropertyName - 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.
      • requireIdentifierOrUniqueKeyType

        protected Type requireIdentifierOrUniqueKeyType​(Mapping mapping)