public class ObjectSerializeUserType extends Object implements org.hibernate.usertype.UserType, Serializable
自定义hibernate数据类型 在Hibernate in Action一书中讲自定义hibernate数据类型因成为开发者的基础技能。 个人感觉在hibernate中有多少种数据类型还没搞清楚了,还去自定义数据类型。。。。 Object序列化/反序列化 数据库中以hex字符串存储 使用示例 将@Type(type="com.centit.oa.common.hibernate.type.ObjectSerializeUserType")注解到bean的属性或get上去
| 构造器和说明 |
|---|
ObjectSerializeUserType() |
| 限定符和类型 | 方法和说明 |
|---|---|
Object |
assemble(Serializable cached,
Object o) |
Object |
deepCopy(Object o)
提供自定义类型的完全复制方法
本方法将用构造返回对象
当nullSafeGet方法调用之后,我们获得了自定义数据对象,在向用户返回自定义数据之前,
deepCopy方法将被调用,它将根据自定义数据对象构造一个完全拷贝,并将此拷贝返回给用户
此时我们就得到了自定义数据对象的两个版本,第一个是从数据库读出的原始版本,其二是我们通过
deepCopy方法构造的复制版本,原始的版本将有Hibernate维护,复制版由用户使用。
|
Serializable |
disassemble(Object value) |
boolean |
equals(Object o,
Object o1) |
int |
hashCode(Object o) |
boolean |
isMutable()
本类型实例是否可变
|
Object |
nullSafeGet(ResultSet rs,
String[] names,
org.hibernate.engine.spi.SharedSessionContractImplementor session,
Object owner)
从JDBC ResultSet读取数据,将其转换为自定义类型后返回
(此方法要求对克能出现null值进行处理)
names中包含了当前自定义类型的映射字段名称
|
void |
nullSafeSet(PreparedStatement st,
Object value,
int index,
org.hibernate.engine.spi.SharedSessionContractImplementor session)
本方法将在Hibernate进行数据保存时被调用
我们可以通过PreparedStateme将自定义数据写入到对应的数据库表字段
|
Object |
replace(Object original,
Object target,
Object owner) |
Class<?> |
returnedClass() |
int[] |
sqlTypes() |
public int[] sqlTypes()
sqlTypes 在接口中 org.hibernate.usertype.UserTypepublic Class<?> returnedClass()
returnedClass 在接口中 org.hibernate.usertype.UserTypepublic boolean equals(Object o, Object o1) throws org.hibernate.HibernateException
equals 在接口中 org.hibernate.usertype.UserTypeorg.hibernate.HibernateExceptionpublic int hashCode(Object o) throws org.hibernate.HibernateException
hashCode 在接口中 org.hibernate.usertype.UserTypeorg.hibernate.HibernateExceptionpublic Object nullSafeGet(ResultSet rs, String[] names, org.hibernate.engine.spi.SharedSessionContractImplementor session, Object owner) throws org.hibernate.HibernateException, SQLException
nullSafeGet 在接口中 org.hibernate.usertype.UserTypers - ResultSetnames - String[]session - SharedSessionContractImplementorowner - Objectorg.hibernate.HibernateException - HibernateExceptionSQLException - SQLExceptionpublic void nullSafeSet(PreparedStatement st, Object value, int index, org.hibernate.engine.spi.SharedSessionContractImplementor session) throws org.hibernate.HibernateException, SQLException
nullSafeSet 在接口中 org.hibernate.usertype.UserTypest - PreparedStatementvalue - Objectindex - intsession - SharedSessionContractImplementororg.hibernate.HibernateException - HibernateExceptionSQLException - SQLExceptionpublic Object deepCopy(Object o) throws org.hibernate.HibernateException
deepCopy 在接口中 org.hibernate.usertype.UserTypeo - Objectorg.hibernate.HibernateException - HibernateExceptionpublic boolean isMutable()
isMutable 在接口中 org.hibernate.usertype.UserTypepublic Serializable disassemble(Object value) throws org.hibernate.HibernateException
disassemble 在接口中 org.hibernate.usertype.UserTypeorg.hibernate.HibernateExceptionpublic Object assemble(Serializable cached, Object o) throws org.hibernate.HibernateException
assemble 在接口中 org.hibernate.usertype.UserTypeorg.hibernate.HibernateExceptionCopyright © 2017 江苏南大先腾信息产业股份有限公司. All rights reserved.