Package org.hibernate.usertype
Interface CompositeUserType
-
public interface CompositeUserTypeA 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.- See Also:
for more simple cases,Type
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Objectassemble(java.io.Serializable cached, SharedSessionContractImplementor session, java.lang.Object owner)Reconstruct an object from the cacheable representation.java.lang.ObjectdeepCopy(java.lang.Object value)Return a deep copy of the persistent state, stopping at entities and at collections.java.io.Serializabledisassemble(java.lang.Object value, SharedSessionContractImplementor session)Transform the object into its cacheable representation.booleanequals(java.lang.Object x, java.lang.Object y)Compare two instances of the class mapped by this type for persistence "equality".java.lang.String[]getPropertyNames()Get the "property names" that may be used in a query.Type[]getPropertyTypes()Get the corresponding "property types".java.lang.ObjectgetPropertyValue(java.lang.Object component, int property)Get the value of a property.inthashCode(java.lang.Object x)Get a hashcode for the instance, consistent with persistence "equality"booleanisMutable()Check if objects of this type mutable.java.lang.ObjectnullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, SharedSessionContractImplementor session, java.lang.Object owner)Retrieve an instance of the mapped class from a JDBC resultset.voidnullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, SharedSessionContractImplementor session)Write an instance of the mapped class to a prepared statement.java.lang.Objectreplace(java.lang.Object original, java.lang.Object target, SharedSessionContractImplementor session, java.lang.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.java.lang.ClassreturnedClass()The class returned by nullSafeGet().voidsetPropertyValue(java.lang.Object component, int property, java.lang.Object value)Set the value of a property.
-
-
-
Method Detail
-
getPropertyNames
java.lang.String[] getPropertyNames()
Get the "property names" that may be used in a query.- Returns:
- an array of "property names"
-
getPropertyTypes
Type[] getPropertyTypes()
Get the corresponding "property types".- Returns:
- an array of Hibernate types
-
getPropertyValue
java.lang.Object getPropertyValue(java.lang.Object component, int property) throws HibernateExceptionGet the value of a property.- Parameters:
component- an instance of class mapped by this "type"property-- Returns:
- the property value
- Throws:
HibernateException
-
setPropertyValue
void setPropertyValue(java.lang.Object component, int property, java.lang.Object value) throws HibernateExceptionSet the value of a property.- Parameters:
component- an instance of class mapped by this "type"property-value- the value to set- Throws:
HibernateException
-
returnedClass
java.lang.Class returnedClass()
The class returned by nullSafeGet().- Returns:
- Class
-
equals
boolean equals(java.lang.Object x, java.lang.Object y) throws HibernateExceptionCompare two instances of the class mapped by this type for persistence "equality". Equality of the persistent state.- Throws:
HibernateException
-
hashCode
int hashCode(java.lang.Object x) throws HibernateExceptionGet a hashcode for the instance, consistent with persistence "equality"- Throws:
HibernateException
-
nullSafeGet
java.lang.Object nullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, SharedSessionContractImplementor session, java.lang.Object owner) throws HibernateException, java.sql.SQLExceptionRetrieve an instance of the mapped class from a JDBC resultset. Implementors should handle possibility of null values.- Parameters:
rs- a JDBC result setnames- the column namessession-owner- the containing entity- Returns:
- Object
- Throws:
HibernateExceptionjava.sql.SQLException
-
nullSafeSet
void nullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, SharedSessionContractImplementor session) throws HibernateException, java.sql.SQLExceptionWrite an instance of the mapped class to a prepared statement. Implementors should handle possibility of null values. A multi-column type should be written to parameters starting from index.- Parameters:
st- a JDBC prepared statementvalue- the object to writeindex- statement parameter indexsession-- Throws:
HibernateExceptionjava.sql.SQLException
-
deepCopy
java.lang.Object deepCopy(java.lang.Object value) throws HibernateExceptionReturn a deep copy of the persistent state, stopping at entities and at collections.- Parameters:
value- generally a collection element or entity field- Returns:
- Object a copy
- Throws:
HibernateException
-
isMutable
boolean isMutable()
Check if objects of this type mutable.- Returns:
- boolean
-
disassemble
java.io.Serializable disassemble(java.lang.Object value, SharedSessionContractImplementor session) throws HibernateExceptionTransform the object into its cacheable representation. At the very least this method should perform a deep copy. 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 cachedsession-- Returns:
- a cacheable representation of the object
- Throws:
HibernateException
-
assemble
java.lang.Object assemble(java.io.Serializable cached, SharedSessionContractImplementor session, java.lang.Object owner) throws HibernateExceptionReconstruct an object from the cacheable representation. At the very least this method should perform a deep copy. (optional operation)- Parameters:
cached- the object to be cachedsession-owner- the owner of the cached object- Returns:
- a reconstructed object from the cacheable representation
- Throws:
HibernateException
-
replace
java.lang.Object replace(java.lang.Object original, java.lang.Object target, SharedSessionContractImplementor session, java.lang.Object owner) throws HibernateExceptionDuring 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. However, since composite user types often define component values, it might make sense to recursively replace component values in the target object.- Throws:
HibernateException
-
-