0

I set up byte code enhancement for Hibernate version 5.2.4-Final as follows:

<plugin>
    <groupId>org.hibernate.orm.tooling</groupId>
    <artifactId>hibernate-enhance-maven-plugin</artifactId>
    <version>${hibernate.version}</version>
    <dependencies>
      <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
      </dependency>
    </dependencies>
    <executions>
      <execution>
        <configuration>
            <failOnError>true</failOnError>
            <enableLazyInitialization>true</enableLazyInitialization>
            <enableDirtyTracking>false</enableDirtyTracking>
            <enableAssociationManagement>false</enableAssociationManagement>
        </configuration>
        <goals>
          <goal>enhance</goal>
        </goals>
      </execution>
    </executions>
</plugin>

I had to add the jta-dependency since I got this error on building my project. Now after building, when I run my tests, it gives me the following error for different classes (seemingly non deterministic) and different attributes. In this example it is the listAttribute in myPackage.MyClass:

    Caused by: org.hibernate.PropertyAccessException: Exception occurred inside setter of myPackage.MyClass.listAttribute
    at org.hibernate.property.access.spi.EnhancedSetterImpl.set(EnhancedSetterImpl.java:86)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:611)
    at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:205)
    at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:4619)
    at org.hibernate.event.internal.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:442)
    at org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:233)
    at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:173)
    at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:69)
    at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:863)
    ... 174 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.hibernate.property.access.spi.EnhancedSetterImpl.set(EnhancedSetterImpl.java:61)
    ... 182 more
Caused by: java.lang.NoSuchMethodError: myPackage.MyClass.$$_hibernate_read_listAttribute()Ljava/util/List;
    at myPackage.MyClass.$$_hibernate_write_listAttribute(MyClass.java)
    ... 187 more

What can I do to get rid of these types of errors?

lasbr
  • 79
  • 1
  • 8

1 Answers1

0

I figured out, what the problem was. If the tests are run in Intellij (or possibly other IDEs) the option to build before running the tests needs to be disabled, otherwise the enhanced classes are overwritten again.

My solution in detail:

Run -> Edit Configurations -> Choose JUnit Test Configuration that should be run -> Modify options (Alt + M) -> Do not build before run

lasbr
  • 79
  • 1
  • 8