-->
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.  [ 5 posts ] 
Author Message
 Post subject: Sorting association data
PostPosted: Mon Jan 07, 2008 10:35 am 
Newbie

Joined: Mon Jan 07, 2008 9:51 am
Posts: 3
Hi.

I have two related objects, Account and LineItem. See end of this post for hibernate mapping data. In "view" type situations I would like to sort the LineItems associated with an account. I would like the user to control the column used for sorting so this sorting must be at run-time, preferably at the database.

I can succesfully sort LineItems at runtime using both HQL and Criteria, however I can only receive a new List of LineItems using this approach. I would like to receive the sorted data within the existing Object graph, that is as an updated collection in an Account object. Is this possible?


Code:
<class name="Account" table="FINANCE_ACCOUNTS">
    <id name="accountID">
        <generator class="increment"/>   
    </id>
    <property name="name"/>
    <property name="type" type="accountType"/>
       
    <set name="lineItems">
      <key column="accountId"/>
      <one-to-many class="LineItem"/>
    </set>
       
    <many-to-one name="user" column="userid"/>       
</class>
<class name="LineItem" table="FINANCE_LINEITEM">
    <id name="lineItemId">
        <generator class="increment"/>         
    </id>
    <property name="description"/>
    <property name="amount"/>
    <property name="postingDate"/>
       
    <many-to-one name="account" column="accountId"/>
</class>   


Many thanks for any help given.


Top
 Profile  
 
 Post subject: Re: Sorting association data
PostPosted: Mon Jan 07, 2008 12:10 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
herbert912,

Your question implies that you are providing some kind of "sorting" feature by using a "disconnected" new collection of children each time.
I advise you not to do that. Issue a new HQL or Criteria instead, with the new sorting. Provided you keep your resultsets reasonably short, let Hibernate and the database do the work, and don't be worrying about whether or not your reshuffled collection will be persisted in an undesirable way.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 12:19 pm 
Newbie

Joined: Mon Jan 07, 2008 9:51 am
Posts: 3
Hi Gonzalo.

Thanks for the response. I perhaps didnt explain my question clearly so let me clarify. So basically I want to retrieve a complete object graph ie Account with associated LineItems as a collection which I will disconnect to pass to the presentation tier. I would like the ability to specify (at runtime) the sorting on the associated LineItems within that graph. I do not want to receive just a collection containing LineItems.

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 12:56 pm 
Newbie

Joined: Wed Mar 15, 2006 8:10 pm
Posts: 2
Does this help?

http://www.hibernate.org/hib_docs/annot ... /Sort.html

Nick


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 1:33 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
So if you already made the design decision to pass a disconnected collection to the presentation tier, (that is, not belonging to the object graph) I don't know what your Hibernate-related question is.

_________________
Gonzalo Díaz


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