org.hibernate.QueryException: No column name found for property [id] for alias [e] [select * from ( select {d.*},{e.*} from department d, employee e where d.department_id = e.department_id ) where {e.id} = 232 ]

Hibernate JIRA | Viral B | 9 years ago
  1. 0

    SQLQueryParser replaces query aliases and property names with corresponding auto generated aliases. The probelm is if we use {aliasName.*} then everything works fine , but along with {aliasName.*} , if you use {aliasName.propertyName} then it doesnot work if the alias is a collection but works if aliasName is an Entity. To testify this I created two hibernate files Employee and Department , Department has many employees I wrote the following testcase, public void testNativeSqlQueryCollectionAliasDefect() { String query = "select * from ( select {d.*},{e.*} " + " from department d, employee e where d.department_id = e.department_id " + " ) where {e.id} = 232 "; getSession().createSQLQuery(query).addEntity("d",Department.class) .addJoin("e","d.employees" ) .list(); } The testcase throws following exception, org.hibernate.QueryException: No column name found for property [id] for alias [e] [select * from ( select {d.*},{e.*} from department d, employee e where d.department_id = e.department_id ) where {e.id} = 232 ] at org.hibernate.loader.custom.sql.SQLQueryParser.resolveCollectionProperties(SQLQueryParser.java:152) at org.hibernate.loader.custom.sql.SQLQueryParser.substituteBrackets(SQLQueryParser.java:98) at org.hibernate.loader.custom.sql.SQLQueryParser.process(SQLQueryParser.java:51) at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:110) at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:47) at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114) at org.hibernate.impl.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:137) at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152) at com.sony.spe.test.nativeSql.TestPageDAO.testNativeSqlQuery(TestPageDAO.java:117) 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 org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128) 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) The following testcase runs fine if instead of {e.id} , we use {d.id} sine alias d is of type entity where as e here is a collection SQLQueryParser.java Line No: 148 columnAliases = collectionPersister.getCollectionPropertyColumnAliases( propertyName, collectionSuffix ); AbstractCollectionPersister.getCollectionPropertyColumnAliases() uses a wrong Map (collectionPropertyColumnAliases) for looking up the property alias, This method is the culprit. Fix: Instead of calling getCollectionPropertyColumnAliases bypass and call resolveProperties which works fine //Existing Code //columnAliases = collectionPersister.getCollectionPropertyColumnAliases( propertyName, collectionSuffix ); //Added: Viral columnAliases = new String[]{resolveProperties(aliasName, propertyName)}; Now the test case wors fine and generates the alias : EMPLOYEE1_0_1_ in the below query select * from ( select d.DEPARTMENT_ID as DEPARTMENT1_1_0_, d.DEPARTMENT_NAME as DEPARTMENT2_1_0_, e.DEPARTMENT_ID as DEPARTMENT3_0__, e.EMPLOYEE_ID as EMPLOYEE1_0__, e.EMPLOYEE_ID as EMPLOYEE1_0_1_, e.EMPLOYEE_NAME as EMPLOYEE2_0_1_ from department d, employee e where d.department_id = e.department_id ) where EMPLOYEE1_0_1_ = 232 I have attached SQLQueryParser fixed and the test domain files I created for testing purpose

    Hibernate JIRA | 9 years ago | Viral B
    org.hibernate.QueryException: No column name found for property [id] for alias [e] [select * from ( select {d.*},{e.*} from department d, employee e where d.department_id = e.department_id ) where {e.id} = 232 ]
  2. 0

    SQLQueryParser replaces query aliases and property names with corresponding auto generated aliases. The probelm is if we use {aliasName.*} then everything works fine , but along with {aliasName.*} , if you use {aliasName.propertyName} then it doesnot work if the alias is a collection but works if aliasName is an Entity. To testify this I created two hibernate files Employee and Department , Department has many employees I wrote the following testcase, public void testNativeSqlQueryCollectionAliasDefect() { String query = "select * from ( select {d.*},{e.*} " + " from department d, employee e where d.department_id = e.department_id " + " ) where {e.id} = 232 "; getSession().createSQLQuery(query).addEntity("d",Department.class) .addJoin("e","d.employees" ) .list(); } The testcase throws following exception, org.hibernate.QueryException: No column name found for property [id] for alias [e] [select * from ( select {d.*},{e.*} from department d, employee e where d.department_id = e.department_id ) where {e.id} = 232 ] at org.hibernate.loader.custom.sql.SQLQueryParser.resolveCollectionProperties(SQLQueryParser.java:152) at org.hibernate.loader.custom.sql.SQLQueryParser.substituteBrackets(SQLQueryParser.java:98) at org.hibernate.loader.custom.sql.SQLQueryParser.process(SQLQueryParser.java:51) at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:110) at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:47) at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114) at org.hibernate.impl.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:137) at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152) at com.sony.spe.test.nativeSql.TestPageDAO.testNativeSqlQuery(TestPageDAO.java:117) 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 org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128) 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) The following testcase runs fine if instead of {e.id} , we use {d.id} sine alias d is of type entity where as e here is a collection SQLQueryParser.java Line No: 148 columnAliases = collectionPersister.getCollectionPropertyColumnAliases( propertyName, collectionSuffix ); AbstractCollectionPersister.getCollectionPropertyColumnAliases() uses a wrong Map (collectionPropertyColumnAliases) for looking up the property alias, This method is the culprit. Fix: Instead of calling getCollectionPropertyColumnAliases bypass and call resolveProperties which works fine //Existing Code //columnAliases = collectionPersister.getCollectionPropertyColumnAliases( propertyName, collectionSuffix ); //Added: Viral columnAliases = new String[]{resolveProperties(aliasName, propertyName)}; Now the test case wors fine and generates the alias : EMPLOYEE1_0_1_ in the below query select * from ( select d.DEPARTMENT_ID as DEPARTMENT1_1_0_, d.DEPARTMENT_NAME as DEPARTMENT2_1_0_, e.DEPARTMENT_ID as DEPARTMENT3_0__, e.EMPLOYEE_ID as EMPLOYEE1_0__, e.EMPLOYEE_ID as EMPLOYEE1_0_1_, e.EMPLOYEE_NAME as EMPLOYEE2_0_1_ from department d, employee e where d.department_id = e.department_id ) where EMPLOYEE1_0_1_ = 232 I have attached SQLQueryParser fixed and the test domain files I created for testing purpose

    Hibernate JIRA | 9 years ago | Viral B
    org.hibernate.QueryException: No column name found for property [id] for alias [e] [select * from ( select {d.*},{e.*} from department d, employee e where d.department_id = e.department_id ) where {e.id} = 232 ]
  3. 0

    Error: Not all named parameters have been set (while filtering TAB with filter condition)

    openxava | 4 years ago | raydev
    java.lang.IllegalArgumentException: org.hibernate.QueryException: Not all named parameters have been set: [p2] [SELECT e.id, e.id, e.createdate, e.remarks from Ordine e where e.companyVat= :p0 AND e.companyZipCode= :p1 AND e.status='TO_BE_CONFIRMED' AND e.id = :p2 order by e.id desc]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Error: Not all named parameters have been set (while filtering TAB with filter condition)

    openxava | 4 years ago | raydev
    java.lang.IllegalArgumentException: org.hibernate.QueryException: Not all named parameters have been set: [p2] [SELECT e.id, e.id, e.createdate, e.remarks from Ordine e where e.companyVat= :p0 AND e.companyZipCode= :p1 AND e.status='TO_BE_CONFIRMED' AND e.id = :p2 order by e.id desc]
  6. 0

    select results based on value of foreign key

    Stack Overflow | 10 months ago | MarwenBta
    java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: region_id_region of: com.springJPA.domain.Actels [Select DISTINCT e from com.springJPA.domain.Actels e where e.region_id_region = ?1 ORDER BY e.id_actels ASC]

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.hibernate.QueryException

      No column name found for property [id] for alias [e] [select * from ( select {d.*},{e.*} from department d, employee e where d.department_id = e.department_id ) where {e.id} = 232 ]

      at org.hibernate.loader.custom.sql.SQLQueryParser.resolveCollectionProperties()
    2. Hibernate
      SQLCustomQuery.<init>
      1. org.hibernate.loader.custom.sql.SQLQueryParser.resolveCollectionProperties(SQLQueryParser.java:152)
      2. org.hibernate.loader.custom.sql.SQLQueryParser.substituteBrackets(SQLQueryParser.java:98)
      3. org.hibernate.loader.custom.sql.SQLQueryParser.process(SQLQueryParser.java:51)
      4. org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:110)
      4 frames
    3. Hibernate
      SQLQueryImpl.list
      1. org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:47)
      2. org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114)
      3. org.hibernate.impl.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:137)
      4. org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
      5. org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
      5 frames
    4. com.sony.spe
      TestPageDAO.testNativeSqlQuery
      1. com.sony.spe.test.nativeSql.TestPageDAO.testNativeSqlQuery(TestPageDAO.java:117)
      1 frame
    5. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      4. java.lang.reflect.Method.invoke(Method.java:585)
      4 frames
    6. JUnit
      TestCase.run
      1. junit.framework.TestCase.runTest(TestCase.java:154)
      2. junit.framework.TestCase.runBare(TestCase.java:127)
      3. junit.framework.TestResult$1.protect(TestResult.java:106)
      4. junit.framework.TestResult.runProtected(TestResult.java:124)
      5. junit.framework.TestResult.run(TestResult.java:109)
      6. junit.framework.TestCase.run(TestCase.java:118)
      6 frames
    7. JUnit3 Runner
      RemoteTestRunner.main
      1. org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
      2. org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
      4. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
      5. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
      6. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
      6 frames