我有一张图片
:
public class Picture implements java.io.Serializable {
private byte[] picEncoded;
private String Name;
//etc
有没有可能在不在数据库中创建物理分离表的情况下将byte[]
移动到另一个类中?我需要使用一些继承策略吗?
编辑
在单独的实体中使用Blob:
POJO:
public class PictureBlob implements java.io.Serializable {
private Integer pictureBlobId;
private byte[] blob;
hbm::
<class name="PictureBlob" table="PICTURE">
<id name="pictureBlobId" type="int">
<column length="200" name="PictureID"/>
</id>
<property name="blob" type="byte[]" insert="false" update="false">
<column name="PicEncoded" not-null="false"/>
</property>
</class>
Picture:
hbm::
<one-to-one class="PictureBlob" constrained="true" name="pictureBlob" fetch="select"/>
我该如何插入新图片?
PictureBlob pictureBlob= new PictureBlob();
pictureBlob.setBlob(new byte[]{84,32,22});
Picture p = new Picture();
p.setPictureBlob(pictureBlob);
session.save(p);
插入记录,其中Blob值为空。