byte[] as the version attribute broken

Description

Since and redesign of types, the type descriptor for byte[] is PrimitiveByteArrayTypeDescriptor. So when you declare an attribute of this type in an entity, Hibernate will use a BinaryType to map it. When it comes to getting the versionComparator, it will call this:

return PrimitiveByteArrayTypeDescriptor.INSTANCE.getComparator();

Now when you come to look to how this INSTANCE is built, the constructor AbstractTypeDescriptor(Class<T> type, MutabilityPlan<T> mutabilityPlan) is called with arguments equals to:

byte[].class, ArrayMutabilityPlan.INSTANCE

And then comes the comparator affectation:

Now the problem is that Comparable.class.isAssignableFrom( byte[].class) returns false, meaning that starting with Hibernate 3.6.0 and further, it becomes impossible to use a byte[] attribute as the version mapper when determining if an element can be inserted in second level cache?

Or maybe I am missing something. This is quite critical for us as we are trying to migrate to more recent versions of hibernate and almost all of our version attributes are of the kind

// entity attribute
private byte[] timestamp;

// hbm.xml
<version type="binary" name="timestamp" generated="always" unsaved-value="undefined">
<column name="timestamp" />
</version>

Environment

Hibernate 3.6.0 and further

Activity

Show:
Gail Badner
March 3, 2016, 2:29 AM

This will be fixed by HHH-8999.

Gail Badner
June 21, 2016, 6:15 AM

Reopening as this issue will not be fixed by

Gail Badner
June 29, 2016, 4:01 AM

I've added a new type, org.hibernate.type.RowVersionType, that will automatically be used for byte[] versions/timestamps. RowVersionType implements VersionType.

This fix includes deprecation of VersionType method implementations in org.hibernate.type.BinaryType, since BinaryType will no longer be used for byte[] versions/timestamps.

VersionType implementation of BinaryType will be removed by HHH-10902.

Gail Badner
June 29, 2016, 6:29 AM

Fixed in master, 5.1, and 5.0 branches.

Aldian
June 29, 2016, 3:59 PM

Thanks for your efforts in fixing the problem

Assignee

Gail Badner

Reporter

Aldian

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Minor
Configure