getSessionFactory().getCurrentSession() .createQuery("delete from FunctionResourcePermissionData " + " where id.elementaryResourceId=:elemRes" + " and id.compositeResourceId=:compRes " + " and id.functionId=:fnId") .setInteger("elemRes",fId.getElementaryResourceId().intValue()) .setInteger("compRes",fId.getElementaryResourceId().intValue()) .setInteger("fnId",fId.getElementaryResourceId().intValue()) .executeUpdate();
I'm getting the following exception org.hibernate.exception.SQLGrammarException: could not execute update query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.hql.ast.UpdateStatementExecutor.execute(UpdateStatementExecutor.java:99) at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:297) at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:871) at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:89) at com.wellpoint.eps.epds.data.application.dao.hibernate.AuditLogDAOImplTest.testDelete(AuditLogDAOImplTest.java:92) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60) at java.lang.reflect.Method.invoke(Method.java:391) 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 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/LINUX] SQL0206N "FUNCTIONRE0_.RSRC_ID" is not valid in the context where it is used. SQLSTATE=42703
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown Source) at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown Source) at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_return_code(Unknown Source) at COM.ibm.db2.jdbc.app.DB2PreparedStatement.execute2(Unknown Source) at COM.ibm.db2.jdbc.app.DB2PreparedStatement.executeUpdate(Unknown Source) at org.hibernate.hql.ast.UpdateStatementExecutor.execute(UpdateStatementExecutor.java:76) ... 18 more
The query generated by hibernate is
Hibernate: delete from EPDS.FUNC_RSRC_PRMSN where functionre0_.RSRC_ID=? and functionre0_.CMPST_RSRC_ID=? and functionre0_.FUNC_ID=?
In the query the alias name functionre0_ is not there after the table name ,but before field names the alias name is added.
Hi too late i guess to answer your Query, but lets leave the Answer for the question
Would you modify the Query as below & test : Adding the Alias (FRPD) to the Table name FunctionResourcePermissionData and then using this Alias with the 'id' property.
getSessionFactory().getCurrentSession() .createQuery("delete from FunctionResourcePermissionData FRPD" + " where FRPD.id.elementaryResourceId=:elemRes" + " and FRPD.id.compositeResourceId=:compRes " + " and FRPD.id.functionId=:fnId") .setInteger("elemRes",fId.getElementaryResourceId().intValue()) .setInteger("compRes",fId.getElementaryResourceId().intValue()) .setInteger("fnId",fId.getElementaryResourceId().intValue()) .executeUpdate(); FRPD