[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3150) "ORA-00918: column ambiguously defined" on MERGE/UPDATE when using Joined Subclasses strategy.

Peter Lupo (JIRA) noreply at atlassian.com
Sun Mar 2 11:51:33 EST 2008


"ORA-00918: column ambiguously defined" on MERGE/UPDATE when using Joined Subclasses strategy.
----------------------------------------------------------------------------------------------

                 Key: HHH-3150
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3150
             Project: Hibernate3
          Issue Type: Bug
          Components: core
    Affects Versions: 3.2.6
         Environment: Core 3.2.5, Annotations 3.3.0.GA, EntityManager 3.3.1.GA, Oracle10g Express and MS SQL Server 2005.
            Reporter: Peter Lupo
         Attachments: FromElementType.java

When using Joined Subclass strategy, an entityManager.merge(detatchedSubclassInstance) on a subclass instance result in a query like this:

insert into HT_TB_AMBIENTECONFIGURADO select ambienteco0_.ID as ID from TB_AMBIENTECONFIGURADO ambienteco0_ inner join TB_AMBIENTE ambienteco0_1_ on ambienteco0_.ID=ambienteco0_1_.ID where ID=33367

The "WHERE" condition is not using the table alias. The join is made on the same column, so it shouldn't matter from which table it would be get. Even then, Oracle complains with "ORA-00918: column ambiguously defined" as in the stacktrace included at the end of this description.

The fix is presented by someone with the same problem on a MS SQL Server 2005 database here: http://forums.hibernate.org/viewtopic.php?t=969471

I have applied his fix and tested. It works correctly, generating a query with the table alias. The fixed class is attached with commentaries marking what has been changed (lines 374 to 383).

javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert/select ids for bulk update
	at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
	at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:59)
	at br.ufrj.cos.lens.taba.controle.gerencia.ambiente.CriaEntity.criaAmbConf(CriaEntity.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
	at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
	at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
	at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
	at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
	at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
	at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
	at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
	at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
	at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.exception.SQLGrammarException: could not insert/select ids for bulk update
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
	at org.hibernate.hql.ast.exec.MultiTableUpdateExecutor.execute(MultiTableUpdateExecutor.java:127)
	at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
	at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
	at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
	at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
	at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:50)
	... 21 more
Caused by: java.sql.SQLException: ORA-00918: column ambiguously defined

	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
	at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
	at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
	at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1120)
	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1279)
	at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3415)
	at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3498)
	at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:251)
	at org.hibernate.hql.ast.exec.MultiTableUpdateExecutor.execute(MultiTableUpdateExecutor.java:118)
	... 26 more

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list