-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: cannot order by on a col in an association w/outer-join=true
PostPosted: Wed Feb 16, 2005 12:34 pm 
Newbie

Joined: Wed Feb 16, 2005 12:04 pm
Posts: 3
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


Top
 Profile  
 
 Post subject: answer: RTFM
PostPosted: Wed Feb 16, 2005 5:09 pm 
Newbie

Joined: Wed Feb 16, 2005 12:04 pm
Posts: 3
thee answer is RTFM : section 12.4 Associations:

You may easily specify constraints upon related entities by navigating associations using createCriteria().

List cats = sess.createCriteria(Cat.class)
.add( Expression.like("name", "F%")
.createCriteria("kittens")
.add( Expression.like("name", "F%")
.list();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.