Package org.hibernate.usertype
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 thatproperties[i].name < properties[i + 1].name
for alli >= 0
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description J
assemble(Serializable cached, Object owner)
Reconstruct an object from the cacheable representation.J
deepCopy(J value)
Return a deep copy of the persistent state, stopping at entities and at collections.Serializable
disassemble(J value)
Transform the object into its cacheable representation.Class<?>
embeddable()
The class that represents the embeddable mapping of the type.boolean
equals(J x, J y)
Compare two instances of the class mapped by this type for persistence "equality".Object
getPropertyValue(J component, int property)
Get the value of a property.int
hashCode(J x)
Get a hashcode for the instance, consistent with persistence "equality"J
instantiate(ValueAccess values, SessionFactoryImplementor sessionFactory)
Create an instance of the embeddabledefault boolean
isInstance(Object object, SessionFactoryImplementor sessionFactory)
Performs and "instance of" check to see if the given object is an instance of managed structureboolean
isMutable()
Are objects of this type mutable?default boolean
isSameClass(Object object, SessionFactoryImplementor sessionFactory)
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.Class<J>
returnedClass()
The class returned byinstantiate()
.
-
-
-
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
-
instantiate
J instantiate(ValueAccess values, SessionFactoryImplementor sessionFactory)
Description copied from interface:EmbeddableInstantiator
Create an instance of the embeddable- Specified by:
instantiate
in interfaceEmbeddableInstantiator
-
embeddable
Class<?> embeddable()
The class that represents the embeddable mapping of the type.- 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 cachedowner
- 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 mergedmanaged
- the value in the managed entity- Returns:
- the value to be merged
-
isInstance
default boolean isInstance(Object object, SessionFactoryImplementor sessionFactory)
Description copied from interface:Instantiator
Performs and "instance of" check to see if the given object is an instance of managed structure- Specified by:
isInstance
in interfaceInstantiator
- See Also:
Class.isInstance(java.lang.Object)
-
isSameClass
default boolean isSameClass(Object object, SessionFactoryImplementor sessionFactory)
- Specified by:
isSameClass
in interfaceInstantiator
- See Also:
Object.equals(java.lang.Object)
-
-