posts - 31,  comments - 31,  trackbacks - 0

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

只有注册用户登录后才能发表评论。


网站导航:
 
<2006年9月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

常用链接

留言簿(2)

随笔分类

随笔档案

framework

j2me

java

linux

web

其他

友情链接

素材

最新评论

阅读排行榜

评论排行榜