Flush causes update query on field of type Byte[]

Description

I have a field that is mapped as follows:

@Lob
@Column(name = "picture")
private Byte[] picture;

When retrieving the entity with a regular session.load() or criteria.list(), upon session flush, an update statement is issued for the field.

In an interceptor, I can see in the onFlushDirty method that the byte arrays in the currentState en previousState parameters are different objects, but with the same byte-content. All the other objects in currentState and previousState are identical.

My guess is that this causes Hibernate to think the contents of the field changed?

This behavior did not happen in 3.5.5-Final, and because the entity is versioned, upon each retrieval, the version field is incremented, which is highly undesirable.

Environment

Hibernate 3.6.0.Final, Oracle 11g

Activity

Show:
Gail Badner
July 10, 2014, 5:58 AM

Closing resolved issued in preparation for releasing 4.3.6.

Gail Badner
July 10, 2014, 12:21 AM

Fixed in master and 4.3.

Gail Badner
June 26, 2014, 10:45 PM

Thanks for the test case and patch!

KennyC
June 26, 2014, 3:17 PM

Ok, I provided a patch...

Since a test was already created by Gail shortly after reporting this bug and marked with "FailureExpected", I simple had to remove said annotation and lo and behold: the test passes.

The fix is simple: add the descriptor-specific equals/hashcode functions to ByteArrayTypeDescriptor.java: it seems that they were already present in the 3 other classes for handling char[], Character[] and byte[] lobs, but mysteriously missing from the affected class for handling Byte[].

Can we please have this included in the next release?

KennyC
June 26, 2014, 11:20 AM
Edited

Updated the test case: please remove upload hhh-5811.zip from today and the wrongly uploaded hhh-9257-updated.zip

Fixed

Assignee

Gail Badner

Reporter

KennyC

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major