Save This Page
Home » hibernate-core-src-20081106 » org.hibernate » usertype » [javadoc | source]
org.hibernate.usertype
public interface: UserType [javadoc | source]

All Known Implementing Classes:
    EnhancedUserType, EnumType, UserVersionType, StringClobType, CharacterArrayClobType, PrimitiveCharacterArrayClobType, RevisionTypeType

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
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.
Method from org.hibernate.usertype.UserType Summary:
assemble,   deepCopy,   disassemble,   equals,   hashCode,   isMutable,   nullSafeGet,   nullSafeSet,   replace,   returnedClass,   sqlTypes
Method from org.hibernate.usertype.UserType Detail:
 public Object assemble(Serializable cached,
    Object owner) throws HibernateException
    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)
 public Object deepCopy(Object value) throws HibernateException
    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.
 public Serializable disassemble(Object value) throws HibernateException
    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)
 public boolean equals(Object x,
    Object y) throws HibernateException
    Compare two instances of the class mapped by this type for persistence "equality". Equality of the persistent state.
 public int hashCode(Object x) throws HibernateException
    Get a hashcode for the instance, consistent with persistence "equality"
 public boolean isMutable()
    Are objects of this type mutable?
 public Object nullSafeGet(ResultSet rs,
    String[] names,
    Object owner) throws HibernateException, SQLException
    Retrieve an instance of the mapped class from a JDBC resultset. Implementors should handle possibility of null values.
 public  void nullSafeSet(PreparedStatement st,
    Object value,
    int index) throws HibernateException, SQLException
    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.
 public Object replace(Object original,
    Object target,
    Object owner) throws HibernateException
    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.
 public Class returnedClass()
    The class returned by nullSafeGet().
 public int[] sqlTypes()
    Return the SQL type codes for the columns mapped by this type. The codes are defined on java.sql.Types.