From: <leg...@at...> - 2003-12-02 04:14:15
|
Message: A new issue has been created in JIRA. --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-513 Here is an overview of the issue: --------------------------------------------------------------------- Key: HB-513 Summary: QueryException using composite elements Type: Bug Status: Unassigned Priority: Minor Project: Hibernate2 Components: core Versions: 2.1 rc1 Assignee: Reporter: Matt Read Created: Mon, 1 Dec 2003 4:14 PM Updated: Mon, 1 Dec 2003 4:14 PM Environment: Hibernate 2.1rc1 Sun JDK 1.4.2_01 on Windows XP Description: 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) --------------------------------------------------------------------- JIRA INFORMATION: 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 If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira |