public interface UserType
This interface should be implemented by user-defined "types". A "type" class is <em>not</em> the actual property type - it is a class that knows how to serialize instances of another class to and from JDBC.<br> <br> This interface <ul> <li>abstracts user code from future changes to the <tt>Type</tt> interface,</li> <li>simplifies the implementation of custom types and</li> <li>hides certain "internal" interfaces from user code.</li> </ul> <br> Implementors must be immutable and must declare a public default constructor.<br> <br> The actual class mapped by a <tt>UserType</tt> may be just about anything.<br> <br> <tt>CompositeUserType</tt> provides an extended version of this interface that is useful for more complex cases.<br> <br> Alternatively, custom types could implement <tt>Type</tt> directly or extend one of the abstract classes in <tt>org.hibernate.type</tt>. This approach risks future incompatible changes to classes or interfaces in that package.
for more complex cases
,
Type
Modifier and Type | Method and Description |
---|---|
Object |
assemble(Serializable cached,
Object owner)
Reconstruct an object from the cacheable representation.
|
Object |
deepCopy(Object value)
Return a deep copy of the persistent state, stopping at entities and at
collections.
|
Serializable |
disassemble(Object value)
Transform the object into its cacheable representation.
|
boolean |
equals(Object x,
Object y)
Compare two instances of the class mapped by this type for persistence "equality".
|
int |
hashCode(Object x)
Get a hashcode for the instance, consistent with persistence "equality"
|
boolean |
isMutable()
Are objects of this type mutable?
|
Object |
nullSafeGet(ResultSet rs,
String[] names,
SharedSessionContractImplementor session,
Object owner)
Retrieve an instance of the mapped class from a JDBC resultset.
|
void |
nullSafeSet(PreparedStatement st,
Object value,
int index,
SharedSessionContractImplementor session)
Write an instance of the mapped class to a prepared statement.
|
Object |
replace(Object original,
Object target,
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.
|
Class |
returnedClass()
The class returned by <tt>nullSafeGet()</tt>.
|
int[] |
sqlTypes()
Return the SQL type codes for the columns mapped by this type.
|
int[] sqlTypes()
Return the SQL type codes for the columns mapped by this type. The codes are defined on <tt>java.sql.Types</tt>.
Types
Class returnedClass()
The class returned by <tt>nullSafeGet()</tt>.
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.
x
- y
- HibernateException
int hashCode(Object x) throws HibernateException
Get a hashcode for the instance, consistent with persistence "equality"
HibernateException
Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException
Retrieve an instance of the mapped class from a JDBC resultset. Implementors should handle possibility of null values.
rs
- a JDBC result setnames
- the column namessession
- owner
- the containing entity @return ObjectHibernateException
SQLException
void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) 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 <tt>index</tt>.
st
- a JDBC prepared statementvalue
- the object to writeindex
- statement parameter indexsession
- HibernateException
SQLException
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.
value
- the object to be cloned, which may be nullHibernateException
boolean isMutable()
Are objects of this type mutable?
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)
value
- the object to be cachedHibernateException
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)
cached
- the object to be cachedowner
- the owner of the cached objectHibernateException
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.
original
- the value from the detached entity being mergedtarget
- the value in the managed entityHibernateException
Copyright © 2001-2018 Red Hat, Inc. All Rights Reserved.