向Oracle中插入BLOB类型
使用s2sh框架。实体类:
public class Photo implements java.io.Serializable {// Fieldsprivate Integer id;private Album album;private Timestamp createtime;private String name;private String contentType;private Blob thumbnail;private Blob content;private Integer orderid;private List<Mark> facelookmarks = new ArrayList<Mark>();private Set facelookactivities = new HashSet(0);private List<Comment> facelookcomments = new ArrayList<Comment>();}<property name="content" type="java.sql.Blob"> <column name="CONTENT" /> </property> <property name="thumbnail" type="java.sql.Blob"> <column name="THUMBNAIL" /> </property>
FileInputStream fis = new FileInputStream(this.photoUpload);ByteArrayOutputStream out = new ByteArrayOutputStream();byte[] b = new byte[1024];int n;while ((n=fis.read(b)) != -1) {out.write(b,0,n);}fis.close();out.close();byte[] content = out.toByteArray();this.photo.setAlbum(this.album);this.photo.setContentType(this.photoUploadContentType);this.photo.setCreatetime(new Timestamp(System.currentTimeMillis()));this.photo.setOrderid(orderId);this.photo.setContent(Hibernate.createBlob(content));this.photo.setThumbnail(Hibernate.createBlob(thumbnail));getSession().save(photo);getSession().flush();// 调用flush方法,强制Hibernate立即执行insert sqlgetSession().refresh(photo, LockMode.UPGRADE);// 通过refresh方法,强制Hibernate执行select for update