Thursday, July 1, 2010

Blob fails with merge on Hibernate 3.x

Problem description :
Blob fails with merge on Hibernate 3.x.
Blobs are saved correctly using saveOrUpdate(). Few days back I downloaded the latest version of Hibernate ( i.e. 3.5.3) and had a look at the org.hibernate.type.BlobType class .I found out the replace method written as ...

/**
* {@inheritDoc}
*/
public Object replace(
Object original,
Object target,
SessionImplementor session,
Object owner,
Map copyCache) throws HibernateException {
//Blobs are ignored by merge()
return target;
}

It is already commented out there,that Blobs are ignored :(

Analysis :

First of all, I am not sure it is a bug or not. If you check Hibernate forum here
It is clearly mentioned by one of the Hibernate team members ...
'As per the EJB3 spec
"Fields or properties of type java.sql.Blob and java.sql.Clob are ignored by the merge operation"
But we should not throw any exception and we should explicit it in the doc if not yet..'

But then, if it is not a bug then what about this JIRA entry ?

Workaround :
For the time being use saveOrUpdate or save for Blob,Clob etc.

No comments:

Post a Comment