2

I am using Eclipselink and I have a JPA Entity that is basically a byte array of gzipped data stored as a blob in the database. However, this data is wrapped in a class that manages the byte array and can decode it correctly (GzipByteArray). I used the @Converter and @Convert annotations to convert from the internal byte[] array in the database to my GzipByteArray wrapper class. The Entity actually stores the GzipByteArray class as the variable type. That all works OK.

However, when I want to append some text to the GzipByteArray, I call a method on it to append the text. Eclipselink is not detecting the change to this parameter of the parent Entity class.

I put a .equals() and .hashCode() method on my GzipByteArray to make sure it takes into account the change in the internal byte[] array. That doesn't help. Based on my logging statements, .equals() is not even being called by Eclipselink.

The only way I can get the changes to be detected is to create a new instance of GzipByteArray and use the setter to modify it.

I assume that Eclipselink is using the default DeferredChangeDetectionPolicy. How does this work? I even downloaded the source of Eclipselink, but I can't figure it out. Can I manually force this field to be marked as "dirty" somehow? Does the instance ID of the object have to change in order for Eclipselink to detect it?

David I.
  • 4,747
  • 3
  • 26
  • 34

1 Answers1

1

In your converter you need to return true for isMutable(), this will ensure EclipseLink uses deferred change detection. You could also add @Mutable to your mapping.

If possible, it is more efficient if you call the set method when you change the value instead of using mutable. This will allow EclipseLink to use attribute change tracking, instead of having to compare the entire byte-array for changes on every commit.

James
  • 17,965
  • 11
  • 91
  • 146
  • I tried it both ways. If you set isMutable() to true in the converter, or use the @Mutable tag it works. I set both for clarity. In my case, I really wanted to append some text in a streaming manner to my GzipByteArray and not have to construct a new instance. Thanks! – David I. May 17 '12 at 18:39
  • Hello and sorry for digging this up. This answer is correct, but I would like to add something important: this Converter you are talking about refers to the Converter interface from EclipseLink and NOT the standard Converter interface from JPA. It is important to point this out, I would suggest that you edited this answer just to clarify that. And thanks for it. – CarlosGoncalves Jan 24 '23 at 14:47