The gist is that I have a class (PacketEntry) with a one-to-many association to another class (StandardCategory). I'd like to be able to retrieve instances of PacketEntry based on the value of two properties of PacketEntry, and then have the results ordered by a property in the association class (StandardCategory.categoryName).
I have set the many-to-one association to be eager w/outer-join=true, but the query parser cannot resolve the field. Is this even possible via the criteria interface?
Hibernate version:
2.1.8
Mapping documents:
<class name="packet.PacketEntry" table="packet_entry">
<id name="entryId"/>
<property name="packetId" type="long" column="packet_id"/>
<property name="standardId" type="long" column="standard_id"/>
<many-to-one name="category" class="standard.StandardCategory" column="CATEGORY_ID" not-null="false" outer-join="true"/>
</class>
<class name="standard.StandardCategory" table="category">
<id name="requirementCategoryId"/>
<property name="categoryName" type="string" column="CATEGORY_NM"/>
</class>
Code between sessionFactory.openSession() and session.close():
Criterion[] c = new Criterion[2];
Order[] o = new Order[1];
c[0] = Expression.eq("standardId",new Long(1));
c[1] = Expression.eq("packetId",new Long(1));
o[0] = Order.asc("category.categoryName");
Session s = SessionFactoryUtils.getSession(getSessionFactory(), true);
Criteria crit = s.createCriteria(packet.PacketEntry.class);
crit.add(c[0]);
crit.add(c[1]);
crit.addOrder(o[0]);
return crit.list();
Full stack trace of any exception that occurs:
org.springframework.orm.hibernate.HibernateQueryException: could not resolve property: category.categoryName of: packet.PacketEntry; nested exception is net.sf.hibernate.QueryException: could not resolve property: category.categoryName of: packet.PacketEntry net.sf.hibernate.QueryException: could not resolve property: category.categoryName of: packet.PacketEntry
at net.sf.hibernate.persister.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:50)
at net.sf.hibernate.expression.AbstractCriterion.getColumns(AbstractCriterion.java:42)
at net.sf.hibernate.expression.Order.toSqlString(Order.java:37)
at net.sf.hibernate.loader.CriteriaLoader.<init>(CriteriaLoader.java:78)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3642)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
at gov.navy.nmms.dao.BaseDAO.getFilter(BaseDAO.java:200)
at gov.navy.nmms.dao.BilletDAO.getBilletsByPacketAndStandard(BilletDAO.java:46)
at gov.navy.nmms.dao.BilletDAOImpl.getBilletsByPacketAndStandard(BilletDAOImpl.java:95)
at MainTester.main(MainTester.java:49)
Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):
No SQL generated
Debug level Hibernate log excerpt:
no useful log excerpt
|