The hql i'm trying to execute is as follows:
insert into AssetAttribute(asset, libraryAssetAttribute, version) select ASS, LAA, 0 from Asset ASS, LibraryAssetAttribute LAA where ASS.libraryAsset = LAA.libraryAsset and ASS.libraryAsset.assetType.id = 961
The problem as shown below in the stack trace is that in 'ASS.libraryAsset = LAA.libraryAsset' this gets converted into 'library_asset_id=library_asset_id ' with no reference to the containing objects, and so since the field names are identical the database throws an ambiguous field name exception.
Anybody got any idea how i can get around this? (changing field names isn't an option)
The whole generated SQL query is:
insert into dbo.AssetAttribute ( asset_id, library_asset_attribute_id, version ) select asset0_.id as col_0_0_, libraryass1_.id as col_1_0_, 0 as col_2_0_ from dbo.Asset asset0_, dbo.LibraryAssetAttribute libraryass1_, dbo.LibraryAsset libraryass2_ where library_asset_id=libraryass2_.id and library_asset_id=library_asset_id and asset_type_id=961
The stack trace is:
org.hibernate.exception.GenericJDBCException: could not execute update query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:326)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:209)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1147)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at uk.ltd.conntrol.business.asset.dao.hibernate.AssetTypeAttributeDAOHibernate.save(AssetTypeAttributeDAOHibernate.java:63)
at uk.ltd.conntrol.business.asset.service.impl.AssetTypeServiceImpl.save(AssetTypeServiceImpl.java:332)
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:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy4.save(Unknown Source)
at uk.ltd.conntrol.ObjectCreationSupport.getAssetTypeAttribute(ObjectCreationSupport.java:302)
at uk.ltd.conntrol.business.asset.service.impl.AssetTypeDAOTest.testSaveAssetTypeAttribute(AssetTypeDAOTest.java:82)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.SQLException: Ambiguous column name 'library_asset_id'.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:365)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2781)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2224)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:628)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:525)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:487)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:421)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
... 34 more
|