-->
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: Error on ordering by nested subcriteria properties
PostPosted: Mon Feb 26, 2007 9:53 am 
Newbie

Joined: Mon Feb 26, 2007 9:42 am
Posts: 2
Hi,



maybe I'm missing something, but I cannot sort out the problem.


I've three entities (Supplier, Province, Nation):




What follows is just an example of what I would need to do, but it gives the malfunctioning.



Suppose I want the list of the suppliers ordered by the nation code, which I can reach passing through the province (property addressProvince). My province has a property nation of Nation. Nation has code as key and description as property.



This is a simple schema of my relationships:

(Supplier) -------- addressProvince ----> (Province) -------- nation ----> (Nation)



This would be the code to get "list of the suppliers ordered by the nation code"


Code:
        Criteria crit = sess.createCriteria(Supplier.class);
        Criteria critAddressProvince = crit.createCriteria("addressProvince","addressProvince");
        Criteria critAddressNation = critAddressProvince.createCriteria("nation","nation");

        Order order = Order.asc("addressProvince.nation.code");
        crit.addOrder(order);



this works fine.



Now: suppose I would like to get "list of the suppliers ordered by the nation description"


Then, this would be my code:


Code:
        Criteria crit = sess.createCriteria(Supplier.class);
        Criteria critAddressProvince = crit.createCriteria("addressProvince","addressProvince");
        Criteria critAddressNation = critAddressProvince.createCriteria("nation","nation");

        Order order = Order.asc("addressProvince.nation.description");
        crit.addOrder(order);



This is giving me the following error:

Code:
org.hibernate.QueryException: could not resolve property: nation.description of: com.logit.hibernate.Province
   at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:46)
   at org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:61)
   at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)
   at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1346)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:434)


I tried to use the

criteria.setFetchMode(association, FetchMode.JOIN);

but with no success.



I tried to use the

Code:
        Criteria crit = sess.createCriteria(Supplier.class);
        Criteria critAddressProvince = crit.createCriteria("addressProvince","addressProvince");
        Criteria critAddressNation = critAddressProvince.createCriteria("nation","nation");

        Order order = Order.asc("description");
        critAddressNation.addOrder(order);



This works, but is not what I need. As I said my problem is more generic, this example is just a simplificatin of a more generalized issue.


This is not enough for me because in case order by on multiple properties, it would be impossible to define the order.


Suppose I want to order by nation.description and province.description


This

Code:
        Criteria crit = sess.createCriteria(Supplier.class);
        Criteria critAddressProvince = crit.createCriteria("addressProvince","addressProvince");
        Criteria critAddressNation = critAddressProvince.createCriteria("nation","nation");

        critAddressNation.addOrder(Order.asc("description"));
        critAddressProvince.addOrder(Order.asc("description"));



is (obviously) the same of:

Code:
        Criteria crit = sess.createCriteria(Supplier.class);
        Criteria critAddressProvince = crit.createCriteria("addressProvince","addressProvince");
        Criteria critAddressNation = critAddressProvince.createCriteria("nation","nation");

        critAddressProvince.addOrder(Order.asc("description"));
        critAddressNation.addOrder(Order.asc("description"));

.

While

Code:
        Criteria crit = sess.createCriteria(Supplier.class);
        Criteria critAddressProvince = crit.createCriteria("addressProvince","addressProvince");
        Criteria critAddressNation = critAddressProvince.createCriteria("nation","nation");

        crit.addOrder(Order.asc("addressProvince.description"));
        crit.addOrder(Order.asc("addressProvince.nation.description"));



is different (the order depends on the add sequence)

Code:
        Criteria crit = sess.createCriteria(Supplier.class);
        Criteria critAddressProvince = crit.createCriteria("addressProvince","addressProvince");
        Criteria critAddressNation = critAddressProvince.createCriteria("nation","nation");

        crit.addOrder(Order.asc("addressProvince.nation.description"));
        crit.addOrder(Order.asc("addressProvince.description"));


Any help would be appreciated.

Thanks

Marco


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 4:53 pm 
Newbie

Joined: Tue Dec 12, 2006 5:01 am
Posts: 11
Please have a look on this thread and my proposed fix.

Regards
Joerg


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.