FileDocCategorySizeDatePackage
UserType.javaAPI DocHibernate 3.2.55273Mon Mar 21 09:53:58 GMT 2005org.hibernate.usertype

UserType

public interface UserType
This interface should be implemented by user-defined "types". A "type" class is not the actual property type - it is a class that knows how to serialize instances of another class to and from JDBC.

This interface
  • abstracts user code from future changes to the Type interface,
  • simplifies the implementation of custom types and
  • hides certain "internal" interfaces from user code.

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

The actual class mapped by a UserType may be just about anything.

CompositeUserType provides an extended version of this interface that is useful for more complex cases.

Alternatively, custom types could implement Type directly or extend one of the abstract classes in org.hibernate.type. This approach risks future incompatible changes to classes or interfaces in that package.
see
CompositeUserType for more complex cases
see
org.hibernate.type.Type
author
Gavin King

Fields Summary
Constructors Summary
Methods Summary
public java.lang.Objectassemble(java.io.Serializable cached, java.lang.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)

param
cached the object to be cached
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. It is not necessary to copy immutable objects, or null values, in which case it is safe to simply return the argument.

param
value the object to be cloned, which may be null
return
Object a copy

public java.io.Serializabledisassemble(java.lang.Object 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)

param
value the object to be cached
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

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

public booleanisMutable()
Are objects of this type mutable?

return
boolean

public java.lang.ObjectnullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, 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
owner the containing entity
return
Object
throws
HibernateException
throws
SQLException

public voidnullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index)
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
throws
HibernateException
throws
SQLException

public java.lang.Objectreplace(java.lang.Object original, java.lang.Object target, 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. For objects with component values, it might make sense to recursively replace component values.

param
original the value from the detached entity being merged
param
target the value in the managed entity
return
the value to be merged

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

return
Class

public int[]sqlTypes()
Return the SQL type codes for the columns mapped by this type. The codes are defined on java.sql.Types.

see
java.sql.Types
return
int[] the typecodes