public interface

CompositeUserType

org.hibernate.usertype.CompositeUserType

Class Overview

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.

Summary

Public Methods
abstract Object assemble(Serializable cached, SessionImplementor session, Object owner)
Reconstruct an object from the cacheable representation.
abstract Object deepCopy(Object value)
Return a deep copy of the persistent state, stopping at entities and at collections.
abstract Serializable disassemble(Object value, SessionImplementor session)
Transform the object into its cacheable representation.
abstract boolean equals(Object x, Object y)
Compare two instances of the class mapped by this type for persistence "equality".
abstract String[] getPropertyNames()
Get the "property names" that may be used in a query.
abstract Type[] getPropertyTypes()
Get the corresponding "property types".
abstract Object getPropertyValue(Object component, int property)
Get the value of a property.
abstract int hashCode(Object x)
Get a hashcode for the instance, consistent with persistence "equality"
abstract boolean isMutable()
Check if objects of this type mutable.
abstract Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
Retrieve an instance of the mapped class from a JDBC resultset.
abstract void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
Write an instance of the mapped class to a prepared statement.
abstract Object replace(Object original, Object target, SessionImplementor session, 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.
abstract Class returnedClass()
The class returned by nullSafeGet().
abstract void setPropertyValue(Object component, int property, Object value)
Set the value of a property.

Public Methods

public abstract Object assemble (Serializable cached, SessionImplementor session, Object owner)

Reconstruct 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 cached
owner the owner of the cached object
Returns
  • a reconstructed object from the cachable representation

public abstract Object deepCopy (Object value)

Return 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

public abstract Serializable disassemble (Object value, SessionImplementor session)

Transform 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 cached
Returns
  • a cachable representation of the object

public abstract boolean equals (Object x, Object y)

Compare two instances of the class mapped by this type for persistence "equality". Equality of the persistent state.

Returns
  • boolean

public abstract String[] getPropertyNames ()

Get the "property names" that may be used in a query.

Returns
  • an array of "property names"

public abstract Type[] getPropertyTypes ()

Get the corresponding "property types".

Returns
  • an array of Hibernate types

public abstract Object getPropertyValue (Object component, int property)

Get the value of a property.

Parameters
component an instance of class mapped by this "type"
Returns
  • the property value

public abstract int hashCode (Object x)

Get a hashcode for the instance, consistent with persistence "equality"

public abstract boolean isMutable ()

Check if objects of this type mutable.

Returns
  • boolean

public abstract Object nullSafeGet (ResultSet rs, String[] names, SessionImplementor session, Object owner)

Retrieve an instance of the mapped class from a JDBC resultset. Implementors should handle possibility of null values.

Parameters
rs a JDBC result set
names the column names
owner the containing entity
Returns
  • Object
Throws
HibernateException
SQLException
HibernateException

public abstract void nullSafeSet (PreparedStatement st, Object value, int index, SessionImplementor session)

Write 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 statement
value the object to write
index statement parameter index
Throws
HibernateException
SQLException
HibernateException

public abstract Object replace (Object original, Object target, SessionImplementor session, 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. However, since composite user types often define component values, it might make sense to recursively replace component values in the target object.@return

public abstract Class returnedClass ()

The class returned by nullSafeGet().

Returns
  • Class

public abstract void setPropertyValue (Object component, int property, Object value)

Set the value of a property.

Parameters
component an instance of class mapped by this "type"
value the value to set