1

i am having problem updating a blob with hibernate. (i am using Hibernate 3.3.1-GA)

my model have these getters/setters for hibernate, i.e. internally i deal with byte[] so any getter/setter convert the byte[] to blog.

I can create an initial object without problem, but if I try to change the content of the blob, the database column is not updated. I do not get any error message, everything looks fine, except that the database is not updated.

/** do not use, for hibernate only */
public Blob getLogoBinaryBlob() {
    if(logoBinary == null){
        return null;
    }
    return Hibernate.createBlob(logoBinary);
}

/** do not use, for hibernate only */
public void setLogoBinaryBlob(Blob logoBinaryBlob) {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        logoBinary = toByteArrayImpl(logoBinaryBlob, baos);
    } catch (Exception e) {
    }
  }

my hibernate mapping for the blob looks like

<property name="logoBinaryBlob" column="LOGO_BINARY" type="blob" />

The database used is Oracle.

3
  • Are your properties mapped using JPA or just old fashion hibernate property mappings (for instance, <property name="logoBinary" type="blob" column="logo" />). Also which version of Hibernate do you use ? Commented Mar 30, 2010 at 10:12
  • included mapping and version (see above), thanks. Commented Mar 30, 2010 at 10:42
  • hm, i use getHibernateTemplate().merge(object); to update the entry. when reading this post: forum.hibernate.org/viewtopic.php?f=1&t=942365&start=0 it sounds like merge is not possible to use for models with blobs...any workarounds? Commented Mar 30, 2010 at 12:10

2 Answers 2

2

Wow, I was finally able to find the solution for the Update in BLOB data using Hibernate.


session.merge(domain); // changes blob value to 44

Changing it to this fixes the problem:

Domain merged = (Domain) session.merge(domain);
merged.setBlob(Hibernate.createBlob(domain.getBlob().getBinaryStream()));

Thanks to Chris Bredesen for his post.

Sign up to request clarification or add additional context in comments.

1 Comment

i'm not sure, what do you mean with "change blob value to 44" ? i use hibernate 5.3.9 and this problem still exists
0

Ok, what i ended up doing in the end is creating a separate table for the blob, and by any update of the main object, it will delete and create new entries in the separate table. (hence no updates are performed)

Not ideal, but it works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.