Search code examples
javaspringhibernate-5.xhbmhbmxml

Replacement for DirectPropertyAccessor?


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?


Solution

  • 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.