-->
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.  [ 7 posts ] 
Author Message
 Post subject: Sort bag by inherited property
PostPosted: Mon Jun 19, 2006 12:10 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Hi,

I am trying to order a bag by a column of an inherited class but I get a failure during the collection initialisation stating that the column cannot be found.

So, let's say I have a base class called Person and a subclass called Policeman something like this (simplified mapping of course and not politically correct!):

Code:
<class name="Person">
  <property name="Name"/>
  <joined-subclass name="Policeman">
    <property name="Rank"/>
  </joined-subclass>
</class>


and then I have a Station class:

Code:
<class name="Station">
  <bag name="Policemen" order-by="Name">
    <one-to-many class="Policeman"/>
  </bag>
</class>


It doesn't like the fact that I am trying to order by a column in the inherited class...how should I be doing this?

Cheers,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 11:37 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
in these situations, i usually associate Station to the Abstract class Person and then order-by="Name ASC".

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 7:32 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Yeah...of course...the bag is still going to contain Policeman objects. I guess the only problem is if you want to be able to sort by multiple columns from both the abstract and subclass.

It feels like NH should be able to handle this though and allow you to specify the subclass in the mapping file and order by columns in the abstract class.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 8:11 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
Quote:
It feels like NH should be able to handle this though and allow you to specify the subclass in the mapping file and order by columns in the abstract class.

i completely agree. i have many datagrids that show data from parent/child/abstract/concrete objects and sometimes i just punt and tell the users "cant do that yet." i pretty much have two strategies:

1) implement IComparable in the concrete class. this at least allows me to use an order-by on the abstract class, then call collection.Sort() to change the view. it gets me two column headings that i can "sort" on.

2) implement a pretty specific DAO method that allows me to use HQL to sort via fields in either the parent or child class. this really isn't that clean but gets me what i (my users) want in the UI...

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 8:13 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Yep, seems like a common req to me too...and it is more efficient to have the sorting take place at the database instead of in code.

I feel another JIRA coming on...what do you reckon my chances are :-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 8:58 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
in this instance, i think you could get many of the NH users to "vote" for the JIRA once you've created it. i'd be very interested to hear Sergey's thoughts on the request.

if we had ordering in subcritera, then we could create dynamic ICritera that would handle this but we don't have that either:

Code:
return sesion.CreateCriteria(typeof(Person))
    .AddOrder(Order.Asc("Name"))
    .CreateCriteria(typeof(PoliceMan))
        .AddOrder(Order.Desc("Rank"))
        .AddOrder(Order.Desc("NumberOfCollars))
    .List();


you could easily add/remove/rearrange those Order methods as the UI requested.

-d


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 9:28 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Yeah...HQL is the only option there I guess. The problem for me is that I really want to have the ordering on the bag rather than issuing a different query against the model because I use a lot of domain object navigation.

Have submitted a JIRA for this: http://jira.nhibernate.org/browse/NH-646


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.