Replacement for DirectPropertyAccessor?

264 Views Asked by At

I am upgrading a Spring 4.3.2 project to Spring 5.1.5. One of my test cases started failing with the error.

ClassNotFoundException: org.hibernate.property.DirectPropertyAccessor

Which makes sense since it has been deprecated in Hibernate 5.x which is the lowest compatible Hibernate version for Spring 5.x. I am consuming it in my hbm.xml as below:

<class name="Notification"
       table="T_NOTIFICATION"
       lazy="false">

    <id name="id"
        type="integer"
        column="ID"
        unsaved-value="null"
        access="property">
        <generator class="identity"/>
    </id>

    <!-- A versioned entity. -->
    <version name="version"
             column="VERSION"
             access="org.hibernate.property.DirectPropertyAccessor"/>

What should I replace the access field with, to maintain the same behaviour?

2

There are 2 best solutions below

6
M. Deinum On BEST ANSWER

Using access=<class-name> you should only be using that if you have your own custom class you want to use. If you want to use direct field access instead of properties use access="field" instead of what you have now. See also the Hibernate Reference Guide.

Internally your current version will use the DirectPropertyAccessor when upgrading Hibernate it will automatically adapt to the newly introduced other class to use. Now that burden lies with hibernate instead of you having to know the internal API of hibernate.

4
Abhijeet On

The issue is not with Spring version but with Hibernate version.

org.hibernate.property.DirectPropertyAccessor is deprecated in 5.x version of hibernate.

DirectPropertyAccessor should be replaced with either org.hibernate.property.access.internal.PropertyAccessFieldImpl or org.hibernate.property.access.internal.PropertyAccessMixedImplin higher hibernate versions.