2 Replies Latest reply on Jun 6, 2013 8:51 AM by Adam Warski

    PrimaryKeyJoinColumn and referencedColumnName support in ENVERS 3.6.8?

    mohanakartik masi Newbie

      We are using validityauditstrategy so when any insert happens for Margin entity below we expect envers to create historical versions for the same in B_HISTORY and then A_HISTORY and then refer the same in MARGIN_HISTORY.

      But we are getting the following exception.

      Is this model supported by envers in 3.6.8 which is the version we are using ,Or is our annotations correct.

      Entity mragin has a ManytoOne association with A

      Entity A shares primary key from B.

      Thanks

       

       

      @Entity

      @Table(name="MARGIN")

      @Cacheable

      @Audited

      public class Margin extends com.tms.framework.data.jpa.GenericBaseEntity<Long> implements Serializable {

             private static final long serialVersionUID = 1L;

       

             @Id

      @GeneratedValue(generator="MARGINID_GENERATOR")

      @GenericGenerator(name = "MARGINID_GENERATOR", strategy = "com.tms.vsc.data.util.DataSequenceGenerator",parameters={

                 @Parameter(name="sequence_name",value=" MARGIN_SEQ"),

                 @Parameter(name="value_column",value="id"),

      })

             @Column(name="MARGIN_ID")

             private Long id;

       

            

       

             //bi-directional many-to-one association

             @BusinessKey

             @ManyToOne

             @JoinColumn(name="A_GROUP_ID")

             private A a;

      }

            

       

       

      @Entity

      @Table(name="A_SERIES")

      @PrimaryKeyJoinColumn(name="A_GROUP_ID", referencedColumnName="B_GROUP_ID")

      @DiscriminatorValue(value = "1")

      @Cacheable

      @Audited

      public class A extends B implements Serializable {

             private static final long serialVersionUID = 1L;

       

             //bi-directional many-to-one association

             @OneToMany(mappedBy="A")

             private List<Margin> margins;

       

             //bi-directional many-to-one association

             @OneToMany(mappedBy="A")

             private List<Charge> charges;

      }

            

       

       

      @Entity

      @Table(name="B_GROUP")

      @DiscriminatorColumn(name="B_GROUP_ID", discriminatorType=DiscriminatorType.INTEGER)

      @Inheritance(strategy = InheritanceType.JOINED)

      @Cacheable

      @Audited

      public abstract class B extends com.tms.framework.data.jpa.GenericBaseEntity<Long> implements Serializable {

             private static final long serialVersionUID = 1L;

       

             @Id

      @GeneratedValue(generator=" GROUPID_GENERATOR")

      @GenericGenerator(name = " GROUPID_GENERATOR", strategy = "com.tms.vsc.data.util.DataSequenceGenerator",parameters={

                 @Parameter(name="sequence_name",value=" GROUP_SEQ"),

      @Parameter(name="value_column",value="id"),

      })

            

      @Column(name="B_GROUP_ID")

      private Long id;

       

       

       

       

        insert

          into

              B_HISTORY

              (REVTYPE, REV_END, SYS_END_TS, B_CD, B_DESC, B_EFF_DT, B_EXP_DT,B_NM, SYS_ACTION_CONTEXT_TXT, SYS_TYPE, SYS_ID, SYS_ROLE_NM, SYS_VERSION_NO, SYS_START_TS, ROLE_ID, TYPE_ID, B_GROUP_ID, REV_START)

          values

              (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

      10:58:11.517 DEBUG     org.hibernate.jdbc.AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)

      10:58:11.517 DEBUG   org.hibernate.jdbc.ConnectionManager:295 - skipping aggressive-release due to flush cycle

      10:58:11.535 DEBUG   org.hibernate.util.JDBCExceptionReporter:225 - could not insert: [com.x.x.x.domain.A_HISTORY] [insert into B_HISTORY (REVTYPE, REV_END, SYS_END_TS, B_CD, B_DESC, B_EFF_DT, B_EXP_DT,B_NM, SYS_ACTION_CONTEXT_TXT, SYS_TYPE, SYS_ID, SYS_ROLE_NM, SYS_VERSION_NO, SYS_START_TS, ROLE_ID, TYPE_ID, B_GROUP_ID, REV_START) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]

      java.sql.SQLException: Invalid column index

                at oracle.jdbc.driver.OraclePreparedStatement.setLongInternal(OraclePreparedStatement.java:4901) ~[ojdbc6.jar:11.2.0.2.0]

                at oracle.jdbc.driver.OraclePreparedStatement.setLong(OraclePreparedStatement.java:4888) ~[ojdbc6.jar:11.2.0.2.0]

                at oracle.jdbc.driver.OraclePreparedStatementWrapper.setLong(OraclePreparedStatementWrapper.java:206) ~[ojdbc6.jar:11.2.0.2.0]

                at weblogic.jdbc.wrapper.PreparedStatement.setLong(PreparedStatement.java:778) ~[com.bea.core.datasource6_1.9.0.0.jar:1.9.0.0]

                at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$1.doBind(BigIntTypeDescriptor.java:52) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:91) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:130) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:317) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2195) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2430) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2874) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.envers.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:158) [hibernate-envers-3.6.8.1.Final.jar:3.6.8.Final]

                at org.hibernate.engine.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:543) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.engine.ActionQueue.beforeTransactionCompletion(ActionQueue.java:216) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.impl.SessionImpl.beforeTransactionCompletion(SessionImpl.java:571) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.jdbc.JDBCContext.beforeTransactionCompletion(JDBCContext.java:250) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.transaction.synchronization.CallbackCoordinator.beforeCompletion(CallbackCoordinator.java:125) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.transaction.synchronization.HibernateSynchronizationImpl.beforeCompletion(HibernateSynchronizationImpl.java:51) [hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at weblogic.transaction.internal.ServerSCInfo.doBeforeCompletion(ServerSCInfo.java:1239) [com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:1214) [com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:116) [com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:1316) [com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:2132) [com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:272) [com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:239) [com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.TransactionManagerImpl.commit(TransactionManagerImpl.java:299) [com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1009) [spring-tx-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) [spring-tx-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) [spring-tx-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:257) [spring-jms-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1058) [spring-jms-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:952) [spring-jms-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                at org.springframework.scheduling.commonj.DelegatingWork.run(DelegatingWork.java:61) [spring-context-support-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                at weblogic.work.j2ee.J2EEWorkManager$WorkWithListener.run(J2EEWorkManager.java:183) [weblogic.jar:10.3.4.0]

                at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207) [com.bea.core.weblogic.workmanager_1.9.0.0.jar:1.9.0.0]

                at weblogic.work.ExecuteThread.run(ExecuteThread.java:176) [com.bea.core.weblogic.workmanager_1.9.0.0.jar:1.9.0.0]

      10:58:11.536  WARN   org.hibernate.util.JDBCExceptionReporter:233 - SQL Error: 17003, SQLState: 99999

      10:58:11.539 ERROR   org.hibernate.util.JDBCExceptionReporter:234 - Invalid column index

      10:58:11.550 DEBUG   org.hibernate.jdbc.ConnectionManager:427 - aggressively releasing JDBC connection

      10:58:11.551 DEBUG   org.hibernate.jdbc.ConnectionManager:464 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]

      10:58:11.689  WARN    org.hibernate.ejb.EntityManagerImpl:138 - Entity Manager closed by someone else (hibernate.transaction.auto_close_session must not be used)

      - trying to recover. Cause: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion: sync=org.hibernate.transaction.synchronization.HibernateSynchronizationImpl@1062360

      could not insert: [com.x.x.x.domain.A_HISTORY]

      org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion: sync=org.hibernate.transaction.synchronization.HibernateSynchronizationImpl@1062360

      could not insert: [com.x.x.x.x.A_HISTORY]

                at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1012) ~[spring-tx-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) ~[spring-tx-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) ~[spring-tx-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:257) ~[spring-jms-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1058) ~[spring-jms-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:952) ~[spring-jms-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                at org.springframework.scheduling.commonj.DelegatingWork.run(DelegatingWork.java:61) [spring-context-support-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                at weblogic.work.j2ee.J2EEWorkManager$WorkWithListener.run(J2EEWorkManager.java:183) [weblogic.jar:10.3.4.0]

                at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207) [com.bea.core.weblogic.workmanager_1.9.0.0.jar:1.9.0.0]

                at weblogic.work.ExecuteThread.run(ExecuteThread.java:176) [com.bea.core.weblogic.workmanager_1.9.0.0.jar:1.9.0.0]

      Caused by: weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion: sync=org.hibernate.transaction.synchronization.HibernateSynchronizationImpl@1062360

      could not insert: [com.x.x.x.x.A_HISTORY]

                at weblogic.transaction.internal.TransactionImpl.throwRollbackException(TransactionImpl.java:1881) ~[com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:345) ~[com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:239) ~[com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.TransactionManagerImpl.commit(TransactionManagerImpl.java:299) ~[com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1009) ~[spring-tx-3.0.6.RELEASE.jar:3.0.6.RELEASE]

                ... 9 common frames omitted

      Caused by: org.hibernate.exception.GenericJDBCException: could not insert: [com.x.x.x.x.A_HISTORY]

                at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2454) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2874) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.envers.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:158) ~[hibernate-envers-3.6.8.1.Final.jar:3.6.8.Final]

                at org.hibernate.engine.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:543) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.engine.ActionQueue.beforeTransactionCompletion(ActionQueue.java:216) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.impl.SessionImpl.beforeTransactionCompletion(SessionImpl.java:571) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.jdbc.JDBCContext.beforeTransactionCompletion(JDBCContext.java:250) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.transaction.synchronization.CallbackCoordinator.beforeCompletion(CallbackCoordinator.java:125) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.transaction.synchronization.HibernateSynchronizationImpl.beforeCompletion(HibernateSynchronizationImpl.java:51) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at weblogic.transaction.internal.ServerSCInfo.doBeforeCompletion(ServerSCInfo.java:1239) ~[com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:1214) ~[com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:116) ~[com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:1316) ~[com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:2132) ~[com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:272) ~[com.bea.core.transaction_2.7.0.0.jar:2.7.0.0]

                ... 12 common frames omitted

      Caused by: java.sql.SQLException: Invalid column index

                at oracle.jdbc.driver.OraclePreparedStatement.setLongInternal(OraclePreparedStatement.java:4901) ~[ojdbc6.jar:11.2.0.2.0]

                at oracle.jdbc.driver.OraclePreparedStatement.setLong(OraclePreparedStatement.java:4888) ~[ojdbc6.jar:11.2.0.2.0]

                at oracle.jdbc.driver.OraclePreparedStatementWrapper.setLong(OraclePreparedStatementWrapper.java:206) ~[ojdbc6.jar:11.2.0.2.0]

                at weblogic.jdbc.wrapper.PreparedStatement.setLong(PreparedStatement.java:778) ~[com.bea.core.datasource6_1.9.0.0.jar:1.9.0.0]

                at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$1.doBind(BigIntTypeDescriptor.java:52) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:91) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:130) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:317) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2195) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2430) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]

                ... 33 common frames omitted