Scenario:
The entity manager and a blob are defined in an entity class as:
@PersistenceContext transiet EntityManager em;
@Basic(fetch=FetchType.LAZY) @Column (insertable=true,updatable=false,name="document") @Blob private Blob doc; public InputStream getDoc() { return doc.getBinaryStream(); }
public void setDoc(InputStream is) { Session hibnernateSession=(Session)em.getDelegate(); LobCreator creator=Hibernate.getLobCreator(hibernateSession); doc=createBlob(is, is.available()); }
... When copying an entity instance called oldAttachment to an instance called newAttachment under Hibernate 4.1.7.Final, we can do something like: newAttachment.setDoc( oldAttachment.getDoc() ); then call save( newAttachment ) to finish the transaction. it works perfectly.
But now under Hibernate 4.2.3.Final, running into exception: java.sql.SQLException: ORA-01407: cannot insert ("ABC"."ACHMENT_TABLE"."DOC") to NULL
To work-round the issue, we have to read through the stream, then passing the stream to the newAttachment something like:
BufferedInputStream bis=new BufferedInputStream( oldAttachment.getDoc() ); ByteArrayOutputStream baso=.... while (....) {.....read/write...}
ByteArrayInputStream bais = new ByteArrayInputStream( baso.toByteArray() ); newAttachment.setDoc( bais ); save( newAttachment ); ....
So I am wondering if it is a bug of 4.2.3.Final or something else.
|