Envers doesn't adequately support the PrimaryKeyJoinColumn

Description

A parent/child entity pair are joined by the @PrimaryKeyJoinColumn annotation in the child class. When inserting an audit row into the child entity's corresponding audit table, the child entity uses the name of the parent's primary key instead of its own primary key. The value is the same, but the column names may be different.

The attached test case uses Widget (parent) and RedWidget (child) to illustrate this issue. Here is the generated SQL:
insert
into
WIDGET_AUD
(REVTYPE, WIDGET_DESC, WIDGET_ID, REV)
values
(?, ?, ?, ?)
Hibernate:
insert
into
RED_WIDGET_AUD
(RED_WIDGET_PROPERTY, WIDGET_ID, REV)
values
(?, ?, ?)

The following exception is returned when an insert of the RedWidget committed:

WARN logExceptions, SQL Error: 904, SQLState: 42000
ERROR logExceptions, ORA-00904: "WIDGET_ID": invalid identifier

ERROR performExecutions, Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: could not insert: [org.jboss.envers.test.entities.RedWidgetEntity_AUD]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2285)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2678)
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:1028)
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.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
at org.jboss.envers.test.PrimaryKeyJoinColumnTest.initData(PrimaryKeyJoinColumnTest.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:398)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:145)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:82)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:167)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:104)
at org.testng.TestRunner.runWorkers(TestRunner.java:712)
at org.testng.TestRunner.privateRun(TestRunner.java:582)
at org.testng.TestRunner.run(TestRunner.java:477)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:324)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:319)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:292)
at org.testng.SuiteRunner.run(SuiteRunner.java:198)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:823)
at org.testng.TestNG.runSuitesLocally(TestNG.java:790)
at org.testng.TestNG.run(TestNG.java:708)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)
Caused by: java.sql.SQLException: ORA-00904: "WIDGET_ID": invalid identifier

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at oracle.jdbc.driver.T2CConnection.checkError(T2CConnection.java:789)
at oracle.jdbc.driver.T2CConnection.checkError(T2CConnection.java:715)
at oracle.jdbc.driver.T2CPreparedStatement.executeForDescribe(T2CPreparedStatement.java:605)
at oracle.jdbc.driver.T2CPreparedStatement.executeForRows(T2CPreparedStatement.java:843)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1270)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3415)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3498)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2268)
... 35 more

Attachments

1

Activity

Brett MeyerMarch 7, 2014 at 10:09 PM

Bulk closing tickets resolved in released versions

Lukasz AntoniakJune 5, 2012 at 10:14 PM

Issue has been resolved together with and HHH-6825.

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Created June 4, 2010 at 11:37 PM
Updated March 7, 2014 at 10:09 PM
Resolved June 5, 2012 at 10:14 PM