FileDocCategorySizeDatePackage
CompositeUserType.javaAPI DocHibernate 3.2.55787Tue Apr 19 15:37:00 BST 2005org.hibernate.usertype

CompositeUserType

public interface CompositeUserType
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.
see
UserType for more simple cases
see
org.hibernate.type.Type
author
Gavin King

Fields Summary
Constructors Summary
Methods Summary
public java.lang.Objectassemble(java.io.Serializable cached, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)
Reconstruct an object from the cacheable representation. At the very least this method should perform a deep copy. (optional operation)

param
cached the object to be cached
param
session
param
owner the owner of the cached object
return
a reconstructed object from the cachable representation
throws
HibernateException

public java.lang.ObjectdeepCopy(java.lang.Object value)
Return a deep copy of the persistent state, stopping at entities and at collections.

param
value generally a collection element or entity field
return
Object a copy
throws
HibernateException

public java.io.Serializabledisassemble(java.lang.Object value, org.hibernate.engine.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)

param
value the object to be cached
param
session
return
a cachable representation of the object
throws
HibernateException

public booleanequals(java.lang.Object x, java.lang.Object y)
Compare two instances of the class mapped by this type for persistence "equality". Equality of the persistent state.

param
x
param
y
return
boolean
throws
HibernateException

public java.lang.String[]getPropertyNames()
Get the "property names" that may be used in a query.

return
an array of "property names"

public org.hibernate.type.Type[]getPropertyTypes()
Get the corresponding "property types".

return
an array of Hibernate types

public java.lang.ObjectgetPropertyValue(java.lang.Object component, int property)
Get the value of a property.

param
component an instance of class mapped by this "type"
param
property
return
the property value
throws
HibernateException

public inthashCode(java.lang.Object x)
Get a hashcode for the instance, consistent with persistence "equality"

public booleanisMutable()
Check if objects of this type mutable.

return
boolean

public java.lang.ObjectnullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)
Retrieve an instance of the mapped class from a JDBC resultset. Implementors should handle possibility of null values.

param
rs a JDBC result set
param
names the column names
param
session
param
owner the containing entity
return
Object
throws
HibernateException
throws
SQLException

public voidnullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, org.hibernate.engine.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.

param
st a JDBC prepared statement
param
value the object to write
param
index statement parameter index
param
session
throws
HibernateException
throws
SQLException

public java.lang.Objectreplace(java.lang.Object original, java.lang.Object target, org.hibernate.engine.SessionImplementor 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. 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.

param
original
param
target
param
session
param
owner
return
throws
HibernateException

public java.lang.ClassreturnedClass()
The class returned by nullSafeGet().

return
Class

public voidsetPropertyValue(java.lang.Object component, int property, java.lang.Object value)
Set the value of a property.

param
component an instance of class mapped by this "type"
param
property
param
value the value to set
throws
HibernateException