net.sf.hibernate.QueryException: could not resolve property: id of: example.AttackDetails [select count(ad) from example.PlayerInGame defender join defender.attackDetails ad where ad.attacker = :attacker and defender = :defender]

hibernate.org | 4 months ago
  1. 0

    Hibernate Community • View topic - Filter() on composite-element's -- possible?

    hibernate.org | 4 months ago
    net.sf.hibernate.QueryException: could not resolve property: id of: example.AttackDetails [select count(ad) from example.PlayerInGame defender join defender.attackDetails ad where ad.attacker = :attacker and defender = :defender]
  2. 0

    The following query using named parameters fails: Query q=session.createQuery("from Location loc where (loc.lonLat.UnitX between :minX and :maxX) order by ABS( loc.lonLat.UnitX - :centX )"); q.setDouble("minX", x - r); q.setDouble("maxX", x + r); q.setDouble("centX", x); Iterator locs = q.iterate(); // Fails with QueryException The final bit with 'centX' causes the problem, as the following query, with the 'centX' removed, succeeds: Query q=session.createQuery("from Location loc where (loc.lonLat.UnitX between :minX and :maxX) order by ABS( loc.lonLat.UnitX )"); q.setDouble("minX", x - r); q.setDouble("maxX", x + r); Iterator locs = q.iterate(); // Succeeds Also, using JDBC-style un-named parameters works: Query q=session.createQuery("from Location loc where (loc.lonLat.UnitX between ? and ?) order by ABS( loc.lonLat.UnitX - ? )"); q.setDouble(0, x - r); q.setDouble(1, x + r); q.setDouble(2, x); Iterator locs = q.iterate(); // Succeeds Both of these two succeeding queries bring back all the results I would expect, with the correct ordering - so none of the function-calls or presence of a parameter in the order-by clause should be illegal. The full stack trace is: net.sf.hibernate.QueryException: Named parameter does not appear in Query: centX [from com.thisbedisonfire.madgag.persistence.Location loc where (loc.lonLat.UnitX between :minX and :maxX) order by ABS( loc.lonLat.UnitX - :centX )] at net.sf.hibernate.hql.QueryTranslator.getNamedParameterLocs(QueryTranslator.java:437) at net.sf.hibernate.hql.QueryTranslator.bindNamedParameters(QueryTranslator.java:817) at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:575) at net.sf.hibernate.hql.QueryTranslator.iterate(QueryTranslator.java:832) at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1436) at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:29) at com.thisbedisonfire.madgag.Main.main(Main.java:105) So, something's going wrong with binding of named parameters... Hope you can help! Roberto S. Tyley

    Hibernate JIRA | 1 decade ago | Roberto S. Tyley
    net.sf.hibernate.QueryException: Named parameter does not appear in Query: centX [from com.thisbedisonfire.madgag.persistence.Location loc where (loc.lonLat.UnitX between :minX and :maxX) order by ABS( loc.lonLat.UnitX - :centX )]
  3. 0

    See also: http://forum.hibernate.org/viewtopic.php?t=924854 I've tried to make this as simple as possible but I can't find any guidelines on exactly what that means. I've included everything I think is needed to recreate the problem but I can probably make up a standalone jar if absolutely necessary. Let me know if this would be useful. Here's 2 Java classes with XDoclet markup, EntityA is a standard entity and AssocationForA is a component used in the many-to-many assocation from Entity to itself. /* * Created on 17-Nov-2003 * */ package gatt.example; import java.util.HashSet; import java.util.Set; /** * @hibernate.class table="EntityA" * proxy = "gatt.example.EntityA" * */ public class EntityA { long id; protected Set association = new HashSet(); /** * @return * * @hibernate.id column="id" * generator-class="increment" * unsaved-value="0" * */ public long getId() { return id; } public void setId(long id) { this.id = id; } /** * * @hibernate.set cascade="all" * lazy="true" * table="Association_To_Self" * @hibernate.collection-key column="entityA_id" * @hibernate.collection-composite-element class="gatt.example.AssociationForA" * * @return */ public Set getAssociation() { return association; } /** * * @param associationForA */ public void setAssociation(Set associationForA) { this.association = associationForA; } } /* * Created on 17-Nov-2003 * */ package gatt.example; import java.util.Date; /** * @hibernate.component * * @author Gatt * */ public class AssociationForA { protected Date date; protected EntityA reverseAssociation; /** * @hibernate.property * * @return Returns the date. */ public Date getDate() { return date; } /** * @param date The date to set. */ public void setDate(Date date) { this.date = date; } /** * @hibernate.many-to-one column="association_id" * not-null="true" * cascade="save-update" * * @return Returns the associated instance. */ public EntityA getReverseAssociation() { return reverseAssociation; } /** * @param attackedBy The attackedBy to set. */ public void setReverseAssociation(EntityA reverseAssociation) { this.reverseAssociation = reverseAssociation; } } Here is the generated mapping file: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="gatt.example.EntityA" table="EntityA" proxy="gatt.example.EntityA" dynamic-update="false" dynamic-insert="false" > <id name="id" column="id" type="long" unsaved-value="0" > <generator class="increment"> </generator> </id> <set name="association" table="Association_To_Self" lazy="true" inverse="false" cascade="all" sort="unsorted" > <key column="entityA_id" /> <composite-element class="gatt.example.AssociationForA" > <property name="date" type="java.util.Date" update="true" insert="true" column="date" /> <many-to-one name="reverseAssociation" class="gatt.example.EntityA" cascade="save-update" outer-join="auto" update="true" insert="true" column="association_id" not-null="true" /> </composite-element> </set> <!-- To add non XDoclet property mappings, create a file named hibernate-properties-EntityA.xml containing the additional properties and place it in your merge dir. --> </class> </hibernate-mapping> And here is the test class: /* * Created on Dec 1, 2003 * */ package gatt.example; import gatt.util.hibernate.HibernateFilter; import junit.framework.TestCase; import net.sf.hibernate.Query; import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; /** * @author Gatt * */ public class EntityATest extends TestCase { public static void main(String[] args) { junit.textui.TestRunner.run(EntityATest.class); } protected void setUp() throws Exception { super.setUp(); } protected void tearDown() throws Exception { super.tearDown(); } /** * Constructor for EntityATest. * * @param arg0 */ public EntityATest(String arg0) { super(arg0); } public void testQuery() { try { SessionFactory sf = HibernateFilter.getSessionFactory(); Session session = sf.openSession(); // get the number of associations Query query = session.createQuery("select count(assoc) from EntityA entityA " + "join entityA.association assoc"); int count = ((Integer) query.iterate().next()).intValue(); } catch (Exception e) { e.printStackTrace(); } } } And finally the error: net.sf.hibernate.QueryException: could not resolve property: id of: gatt.example.AssociationForA [select count(assoc) from gatt.example.EntityA entityA join entityA.association assoc] at net.sf.hibernate.persister.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:38) at net.sf.hibernate.collection.AbstractCollectionPersister.toType(AbstractCollectionPersister.java:678) at net.sf.hibernate.hql.PathExpressionParser.getPropertyType(PathExpressionParser.java:244) at net.sf.hibernate.hql.PathExpressionParser.end(PathExpressionParser.java:283) at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30) at net.sf.hibernate.hql.SelectParser.token(SelectParser.java:140) at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87) at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:114) at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:143) at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30) at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:152) at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:141) at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:287) at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1488) at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1518) at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:33) at gatt.example.EntityATest.testQuery(EntityATest.java:49) 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:324) 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:395) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:279) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:171)

    Hibernate JIRA | 1 decade ago | Matt Read
    net.sf.hibernate.QueryException: could not resolve property: id of: gatt.example.AssociationForA [select count(assoc) from gatt.example.EntityA entityA join entityA.association assoc]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    The following query using named parameters fails: Query q=session.createQuery("from Location loc where (loc.lonLat.UnitX between :minX and :maxX) order by ABS( loc.lonLat.UnitX - :centX )"); q.setDouble("minX", x - r); q.setDouble("maxX", x + r); q.setDouble("centX", x); Iterator locs = q.iterate(); // Fails with QueryException The final bit with 'centX' causes the problem, as the following query, with the 'centX' removed, succeeds: Query q=session.createQuery("from Location loc where (loc.lonLat.UnitX between :minX and :maxX) order by ABS( loc.lonLat.UnitX )"); q.setDouble("minX", x - r); q.setDouble("maxX", x + r); Iterator locs = q.iterate(); // Succeeds Also, using JDBC-style un-named parameters works: Query q=session.createQuery("from Location loc where (loc.lonLat.UnitX between ? and ?) order by ABS( loc.lonLat.UnitX - ? )"); q.setDouble(0, x - r); q.setDouble(1, x + r); q.setDouble(2, x); Iterator locs = q.iterate(); // Succeeds Both of these two succeeding queries bring back all the results I would expect, with the correct ordering - so none of the function-calls or presence of a parameter in the order-by clause should be illegal. The full stack trace is: net.sf.hibernate.QueryException: Named parameter does not appear in Query: centX [from com.thisbedisonfire.madgag.persistence.Location loc where (loc.lonLat.UnitX between :minX and :maxX) order by ABS( loc.lonLat.UnitX - :centX )] at net.sf.hibernate.hql.QueryTranslator.getNamedParameterLocs(QueryTranslator.java:437) at net.sf.hibernate.hql.QueryTranslator.bindNamedParameters(QueryTranslator.java:817) at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:575) at net.sf.hibernate.hql.QueryTranslator.iterate(QueryTranslator.java:832) at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1436) at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:29) at com.thisbedisonfire.madgag.Main.main(Main.java:105) So, something's going wrong with binding of named parameters... Hope you can help! Roberto S. Tyley

    Hibernate JIRA | 1 decade ago | Roberto S. Tyley
    net.sf.hibernate.QueryException: Named parameter does not appear in Query: centX [from com.thisbedisonfire.madgag.persistence.Location loc where (loc.lonLat.UnitX between :minX and :maxX) order by ABS( loc.lonLat.UnitX - :centX )]
  6. 0

    See also: http://forum.hibernate.org/viewtopic.php?t=924854 I've tried to make this as simple as possible but I can't find any guidelines on exactly what that means. I've included everything I think is needed to recreate the problem but I can probably make up a standalone jar if absolutely necessary. Let me know if this would be useful. Here's 2 Java classes with XDoclet markup, EntityA is a standard entity and AssocationForA is a component used in the many-to-many assocation from Entity to itself. /* * Created on 17-Nov-2003 * */ package gatt.example; import java.util.HashSet; import java.util.Set; /** * @hibernate.class table="EntityA" * proxy = "gatt.example.EntityA" * */ public class EntityA { long id; protected Set association = new HashSet(); /** * @return * * @hibernate.id column="id" * generator-class="increment" * unsaved-value="0" * */ public long getId() { return id; } public void setId(long id) { this.id = id; } /** * * @hibernate.set cascade="all" * lazy="true" * table="Association_To_Self" * @hibernate.collection-key column="entityA_id" * @hibernate.collection-composite-element class="gatt.example.AssociationForA" * * @return */ public Set getAssociation() { return association; } /** * * @param associationForA */ public void setAssociation(Set associationForA) { this.association = associationForA; } } /* * Created on 17-Nov-2003 * */ package gatt.example; import java.util.Date; /** * @hibernate.component * * @author Gatt * */ public class AssociationForA { protected Date date; protected EntityA reverseAssociation; /** * @hibernate.property * * @return Returns the date. */ public Date getDate() { return date; } /** * @param date The date to set. */ public void setDate(Date date) { this.date = date; } /** * @hibernate.many-to-one column="association_id" * not-null="true" * cascade="save-update" * * @return Returns the associated instance. */ public EntityA getReverseAssociation() { return reverseAssociation; } /** * @param attackedBy The attackedBy to set. */ public void setReverseAssociation(EntityA reverseAssociation) { this.reverseAssociation = reverseAssociation; } } Here is the generated mapping file: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="gatt.example.EntityA" table="EntityA" proxy="gatt.example.EntityA" dynamic-update="false" dynamic-insert="false" > <id name="id" column="id" type="long" unsaved-value="0" > <generator class="increment"> </generator> </id> <set name="association" table="Association_To_Self" lazy="true" inverse="false" cascade="all" sort="unsorted" > <key column="entityA_id" /> <composite-element class="gatt.example.AssociationForA" > <property name="date" type="java.util.Date" update="true" insert="true" column="date" /> <many-to-one name="reverseAssociation" class="gatt.example.EntityA" cascade="save-update" outer-join="auto" update="true" insert="true" column="association_id" not-null="true" /> </composite-element> </set> <!-- To add non XDoclet property mappings, create a file named hibernate-properties-EntityA.xml containing the additional properties and place it in your merge dir. --> </class> </hibernate-mapping> And here is the test class: /* * Created on Dec 1, 2003 * */ package gatt.example; import gatt.util.hibernate.HibernateFilter; import junit.framework.TestCase; import net.sf.hibernate.Query; import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; /** * @author Gatt * */ public class EntityATest extends TestCase { public static void main(String[] args) { junit.textui.TestRunner.run(EntityATest.class); } protected void setUp() throws Exception { super.setUp(); } protected void tearDown() throws Exception { super.tearDown(); } /** * Constructor for EntityATest. * * @param arg0 */ public EntityATest(String arg0) { super(arg0); } public void testQuery() { try { SessionFactory sf = HibernateFilter.getSessionFactory(); Session session = sf.openSession(); // get the number of associations Query query = session.createQuery("select count(assoc) from EntityA entityA " + "join entityA.association assoc"); int count = ((Integer) query.iterate().next()).intValue(); } catch (Exception e) { e.printStackTrace(); } } } And finally the error: net.sf.hibernate.QueryException: could not resolve property: id of: gatt.example.AssociationForA [select count(assoc) from gatt.example.EntityA entityA join entityA.association assoc] at net.sf.hibernate.persister.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:38) at net.sf.hibernate.collection.AbstractCollectionPersister.toType(AbstractCollectionPersister.java:678) at net.sf.hibernate.hql.PathExpressionParser.getPropertyType(PathExpressionParser.java:244) at net.sf.hibernate.hql.PathExpressionParser.end(PathExpressionParser.java:283) at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30) at net.sf.hibernate.hql.SelectParser.token(SelectParser.java:140) at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87) at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:114) at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:143) at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30) at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:152) at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:141) at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:287) at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1488) at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1518) at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:33) at gatt.example.EntityATest.testQuery(EntityATest.java:49) 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:324) 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:395) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:279) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:171)

    Hibernate JIRA | 1 decade ago | Matt Read
    net.sf.hibernate.QueryException: could not resolve property: id of: gatt.example.AssociationForA [select count(assoc) from gatt.example.EntityA entityA join entityA.association assoc]

    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. net.sf.hibernate.QueryException

      could not resolve property: id of: example.AttackDetails [select count(ad) from example.PlayerInGame defender join defender.attackDetails ad where ad.attacker = :attacker and defender = :defender]

      at net.sf.hibernate.persister.AbstractPropertyMapping.toType()
    2. net.sf.hibernate
      QueryImpl.iterate
      1. net.sf.hibernate.persister.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:35)
      2. net.sf.hibernate.collection.AbstractCollectionPersister.toType(AbstractCollectionPersister.java:701)
      3. net.sf.hibernate.hql.PathExpressionParser.getPropertyType(PathExpressionParser.java:242)
      4. net.sf.hibernate.hql.PathExpressionParser.end(PathExpressionParser.java:281)
      5. net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
      6. net.sf.hibernate.hql.SelectParser.token(SelectParser.java:140)
      7. net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
      8. net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:114)
      9. net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:143)
      10. net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
      11. net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:151)
      12. net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:140)
      13. net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:291)
      14. net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1501)
      15. net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1531)
      16. net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:33)
      16 frames
    3. example
      PlayerInGame.getNumAttacksOn
      1. example.PlayerInGame.getNumAttacksOn(PlayerInGame.java:459)
      1 frame