1、数据实体Bean
public class Temp implements Serializable
{
private java.lang.Long id;
private Blob object; //用于存放对象的Blob
private java.lang.Long userId;
private java.util.Date appendDate;
}
2、hbm影射
<hibernate-mapping package="temp">
<class name="Temp" table="TEMP">
<id name="id" column="ID" type="long">
<generator class="sequence">
<param name="sequence">TEMP_SEQ</param>
</generator>
</id>
<property name="object" column="OBJECT" type="blob" />
<property name="userId" column="USER_ID" type="long" />
<property name="appendDate" column="APPEND_DATE" type="date" />
</class>
</hibernate-mapping>
3、save方法
public void saveTemp( ) throws IOException, ClassNotFoundException, SQLException
{
Temp temp = new Temp();
temp.setUserId(new Long(1));
temp.setAppendDate(new Date());
ByteArrayOutputStream outputstr = new ByteArrayOutputStream();
ObjectOutputStream objOutStr = new ObjectOutputStream( outputstr );
objOutStr.writeObject( contract ); //contract为要保存的对象;
BlobImpl blob = new BlobImpl(outputstr.toByteArray());
temp.setObject( blob );
saveTemp(temp); //将Temp持久化到数据库;
}
4、get方法
public void etTempList() throws IOException, ClassNotFoundException, SQLException
{
List Templist = getTempList( userId);
if( contractTemplist.size() != 0 )
{
Temp temp = ( Temp )Templist.get(0);
ObjectInputStream instr = new ObjectInputStream(temp.getObject().getBinaryStream());
Contract contract = ( Contract )instr.readObject();
}
}
posted on 2006-09-24 16:24
小平 阅读(527)
评论(0) 编辑 收藏 所属分类:
java