Interface CompositeUserType<J>

  • All Superinterfaces:
    EmbeddableInstantiator, Instantiator
    All Known Implementing Classes:
    AbstractTimeZoneStorageCompositeUserType, OffsetDateTimeCompositeUserType, ZonedDateTimeCompositeUserType

    public interface CompositeUserType<J>
    extends EmbeddableInstantiator
    A UserType that may be dereferenced in a query. This interface allows a custom type to define "properties". These need not necessarily correspond to physical JavaBeans style properties.

    A CompositeUserType may be used in almost every way that a component may be used. It may even contain many-to-one associations.

    Implementors must be immutable and must declare a public default constructor.

    Unlike UserType, cacheability does not depend upon serializability. Instead, assemble() and disassemble provide conversion to/from a cacheable representation.
    Properties are ordered by the order of their names i.e. they are alphabetically ordered, such that properties[i].name < properties[i + 1].name for all i >= 0.
    • Method Detail

      • getPropertyValue

        Object getPropertyValue​(J component,
                                int property)
                         throws HibernateException
        Get the value of a property.
        Parameters:
        component - an instance of class mapped by this "type"
        property - the property index
        Returns:
        the property value
        Throws:
        HibernateException
      • embeddable

        Class<?> embeddable()
        The class that represents the embeddable mapping of the type.
        Returns:
        Class
      • returnedClass

        Class<J> returnedClass()
        The class returned by instantiate().
        Returns:
        Class
      • equals

        boolean equals​(J x,
                       J y)
        Compare two instances of the class mapped by this type for persistence "equality". Equality of the persistent state.
      • hashCode

        int hashCode​(J x)
        Get a hashcode for the instance, consistent with persistence "equality"
      • deepCopy

        J deepCopy​(J value)
        Return a deep copy of the persistent state, stopping at entities and at collections. It is not necessary to copy immutable objects, or null values, in which case it is safe to simply return the argument.
        Parameters:
        value - the object to be cloned, which may be null
        Returns:
        Object a copy
      • isMutable

        boolean isMutable()
        Are objects of this type mutable?
        Returns:
        boolean
      • disassemble

        Serializable disassemble​(J value)
        Transform the object into its cacheable representation. At the very least this method should perform a deep copy if the type is mutable. That may not be enough for some implementations, however; for example, associations must be cached as identifier values. (optional operation)
        Parameters:
        value - the object to be cached
        Returns:
        a cacheable representation of the object
      • assemble

        J assemble​(Serializable cached,
                   Object owner)
        Reconstruct an object from the cacheable representation. At the very least this method should perform a deep copy if the type is mutable. (optional operation)
        Parameters:
        cached - the object to be cached
        owner - the owner of the cached object
        Returns:
        a reconstructed object from the cacheable representation
      • replace

        J replace​(J detached,
                  J managed,
                  Object owner)
        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:
        detached - the value from the detached entity being merged
        managed - the value in the managed entity
        Returns:
        the value to be merged