0

I am brand new to Envers - started today. I am extending an existing Spring Boot application with Audit support using Envers. I annotated all @Entity classes and made some changes, as described here Envers + MYSQL + List<String> = SQLSyntaxErrorException: Specified key was too long; All database tables are perfectly created, but when I use a CommandLineRunner to generate test data in the database I get the below Error.

ERROR 17:50 o.s.b.SpringApplication.reportFailure:821: Application run failed 
java.lang.IllegalStateException: Failed to execute CommandLineRunner
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:782)
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:763)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202)
    at com.agiletunes.productmanager.ProdMgrApp.init(ProdMgrApp.java:59)
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:841)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$159(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:541)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:746)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:714)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:534)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:305)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
    at com.agiletunes.productmanager.services.DatabaseTestInitializationService$$EnhancerBySpringCGLIB$$62d47d4b.createTestData(<generated>)
    at com.agiletunes.productmanager.ProdMgrApp.lambda$2(ProdMgrApp.java:129)
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:779)
    ... 8 common frames omitted
Caused by: javax.persistence.RollbackException: Error while committing the transaction
    at org.hibernate.internal.ExceptionConverterImpl.convertCommitException(ExceptionConverterImpl.java:81)
    at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:107)
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:532)
    ... 18 common frames omitted
Caused by: java.lang.NullPointerException: null
    at org.hibernate.envers.event.spi.BaseEnversEventListener.addCollectionChangeWorkUnit(BaseEnversEventListener.java:109)
    at org.hibernate.envers.event.spi.BaseEnversEventListener.generateBidirectionalCollectionChangeWorkUnits(BaseEnversEventListener.java:76)
    at org.hibernate.envers.event.spi.EnversPostInsertEventListenerImpl.onPostInsert(EnversPostInsertEventListenerImpl.java:49)
    at org.hibernate.action.internal.EntityInsertAction.postInsert(EntityInsertAction.java:168)
    at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:135)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:478)
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:356)
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
    at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1454)
    at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:511)
    at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3290)
    at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2486)
    at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:473)
    at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:178)
    at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$300(JdbcResourceLocalTransactionCoordinatorImpl.java:39)
    at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:271)
    at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:104)
    ... 19 common frames omitted
 INFO 17:50 o.s.o.j.AbstractEntityManagerFactoryBean.destroy:597: Closing JPA EntityManagerFactory for persistence unit 'default' 
 INFO 17:50 c.z.h.HikariDataSource.close:350: HikariPool-1 - Shutdown initiated... 
 INFO 17:50 c.z.h.HikariDataSource.close:352: HikariPool-1 - Shutdown completed. 

Before I added Envers, and before I shortend the strings, as explained in the other stackoverflow entry above, I could generate the test data perfectly.

The trouble is that I don't see in the entire stack trace any helpful information where the issue is coming from. How to find out what is the root cause?

Alex
  • 1,387
  • 2
  • 9
  • 14

2 Answers2

2

I tried a number of things, but while I changed here and there, I stumbled over a superclass that was lacking the @Audited annotation. Now it is working perfectly.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
Alex
  • 1,387
  • 2
  • 9
  • 14
0

Interesting question:

How to find out what is the root cause?

The last part of the stack trace which represents the original exception thrown reads:

Caused by: java.lang.NullPointerException: null
    at org.hibernate.envers.event.spi.BaseEnversEventListener.addCollectionChangeWorkUnit(BaseEnversEventListener.java:109)

A first wild guess therefor is that it might have to do with a collection being null. Such a guess is useful if your entity model is small and you can easily check that.

If that doesn't lead to a resolution the next step is to limit the scope.

Remove about half of your entities and check if the problem still exists.

If it does repeat.

If it doesn't try the other half.

This way reduce your model to something really small.

Now remove attributes in the same way until you have a tiny model to reproduce the issue.

Now repeat with the stuff you do with your model, until you have only a few interactions left.

Once your program is so simple often the problem becomes obvious. If it isn't it is a great basis for asking a question here. Or report a bug with Envers.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348