2 Replies Latest reply on Jul 8, 2009 3:10 PM by Jamie Bisotti

    Envers looking for the wrong table name

    Jamie Bisotti Newbie

      I have the following Entities:

      @Audited
      @Entity
      @Table(name="MY_FOO")
      public class MyFoo
      {
       ...
       @Cascade( value={ CascadeType.SAVE_UPDATE, CascadeType.DELETE, CascadeType.DELETE_ORPHAN} )
       @JoinColumn( name="FOO_ID", nullable=false, updateable=false )
       @OneToMany( fetch=FetchType.LAZY )
       private Set<FooSupply> supplies = new HashSet<FooSupply();
       ...
      }
      
      
      @Audited
      @Entity
      @Table( name="FOO_SUPPLIES" )
      public class FooSupply
      {
       ...
      }
      


      In my Hibernate configuration, I specify "_HISTORY" as the table suffix (i.e. org.hibernate.envers.auditTableSuffix)


      These result in both a MY_FOO_HISTORY and a FOO_SUPPLIES_HISTORY table being created. So far, so good.


      However, when I run my application it fails because it seems Envers is looking for the following table:
      MyFoo_FooSupply_HISTORY


      2009-07-06 17:50:14,261 [auditParentTask3309] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null
      2009-07-06 17:50:14,261 [auditParentTask3309] ERROR org.hibernate.util.JDBCExceptionReporter - Borrow prepareStatement from pool failed
      2009-07-06 17:50:14,261 [auditParentTask3309] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
      org.hibernate.exception.GenericJDBCException: could not insert: [MyFoo_FooSupply_HISTORY]
      at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2305)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2698)
      at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1031)
      at org.hibernate.envers.synchronization.AuditSync.beforeCompletion(AuditSync.java:167)
      at org.hibernate.transaction.JDBCTransaction.notifyLocalSynchsBeforeTransactionCompletion(JDBCTransaction.java:274)
      at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:140)
      at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
      ...
      Caused by: org.apache.commons.dbcp.SQLNestedException: Borrow prepareStatement from pool failed
      at org.apache.commons.dbcp.PoolingConnection.prepareStatement(PoolingConnection.java:98)
      at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:248)
      at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:302)
      at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
      at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:116)
      at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
      at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2262)
      ... 35 more
      Caused by: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544569. Dynamic SQL Error
      SQL error code = -204
      Table unknown
      MYFOO_FOOSUPPLY_HISTORY
      At line 1, column 13
      at org.firebirdsql.jdbc.AbstractPreparedStatement.(AbstractPreparedStatement.java:119)
      at org.firebirdsql.jdbc.FBPreparedStatement.(FBPreparedStatement.java:41)
      at sun.reflect.GeneratedConstructorAccessor40.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at org.firebirdsql.jdbc.FBStatementFactory.createPreparedStatement(FBStatementFactory.java:90)
      at org.firebirdsql.jdbc.AbstractConnection.prepareStatement(AbstractConnection.java:869)
      at org.firebirdsql.jdbc.AbstractConnection.prepareStatement(AbstractConnection.java:824)
      at org.firebirdsql.jdbc.AbstractConnection.prepareStatement(AbstractConnection.java:817)
      at org.firebirdsql.jdbc.AbstractConnection.prepareStatement(AbstractConnection.java:293)
      at org.apache.commons.dbcp.PoolingConnection.makeObject(PoolingConnection.java:193)
      at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:964)
      at org.apache.commons.dbcp.PoolingConnection.prepareStatement(PoolingConnection.java:92)
      ... 42 more


      Is this a (known?) bug in Envers?
      Or am I just overlooking something simple?

      Thanks,
      Jamie