hibernate序列化问题
来源:互联网 发布:匡恩网络是个奇葩公司 编辑:程序博客网 时间:2024/05/01 09:36
/*
* 将对象转化成java.sql.Blob
* 要求 对象是序列化的
*/
public java.sql.Blob ObjectToBlob(Object obj) throws IOException{
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream outputStream = new ObjectOutputStream(out);
outputStream.writeObject(obj);
byte [] bytes = out.toByteArray();
outputStream.close();
return Hibernate.createBlob(bytes);
} catch (Exception e) {
// TODO: handle exception
System.out.println( " ObjectToBlob " );
return null ;
}
}
/*
* 将java.sql.Blob 转化成 对象 相应对象
* 要求 对象是序列化的
*/
public Object BlobToObject(java.sql.Blob desblob,Object obj) throws IOException{
try {
ObjectInputStream in = new ObjectInputStream(desblob.getBinaryStream());
obj = in.readObject();
in.close();
return obj;
} catch (Exception e) {
// TODO: handle exception
System.out.println( " BlobToObject " );
e.printStackTrace();
return null ;
}
}
* 将对象转化成java.sql.Blob
* 要求 对象是序列化的
*/
public java.sql.Blob ObjectToBlob(Object obj) throws IOException{
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream outputStream = new ObjectOutputStream(out);
outputStream.writeObject(obj);
byte [] bytes = out.toByteArray();
outputStream.close();
return Hibernate.createBlob(bytes);
} catch (Exception e) {
// TODO: handle exception
System.out.println( " ObjectToBlob " );
return null ;
}
}
/*
* 将java.sql.Blob 转化成 对象 相应对象
* 要求 对象是序列化的
*/
public Object BlobToObject(java.sql.Blob desblob,Object obj) throws IOException{
try {
ObjectInputStream in = new ObjectInputStream(desblob.getBinaryStream());
obj = in.readObject();
in.close();
return obj;
} catch (Exception e) {
// TODO: handle exception
System.out.println( " BlobToObject " );
e.printStackTrace();
return null ;
}
}
0 0
- hibernate序列化问题
- Hibernate映射度联合主键的问题,关于序列化
- 关于hibernate实体类序列化问题记录
- 解决hibernate 序列化死循环的问题
- 关于hibernate级联存储序列问题
- Spring MVC返回hibernate对象序列化json报懒加载出错的问题
- 解决因为hibernate的懒加载引起的json 序列化失败的问题
- 序列化问题
- 序列化NotSerializableException问题
- java 序列化 问题
- 序列化问题!Datatable
- java序列化问题
- 序列化问题
- HashSet序列化问题
- 序列化--画图问题
- Java序列化问题
- 序列化相关问题
- json序列化问题
- HTTP协议—— 简单认识TCP/IP协议
- mysql 基础 ddl dml 总结
- POJ - 1251----Jungle Roads(prim)
- beactiful_code
- 免费java架构师大数据redis 视频
- hibernate序列化问题
- nexus-3.2.0-01.zip安装及使用说明
- spring自动添加注解
- USB host control
- 程序员的自主学习
- linux,go!
- Mysql的索引和慢查询优化
- Android各个版本名称与版本号对照表
- Android酷炫实用的开源框架(UI框架)