-->
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.  [ 10 posts ] 
Author Message
 Post subject: Easy question about <loader> element
PostPosted: Fri May 26, 2006 2:06 pm 
Newbie

Joined: Wed Jan 25, 2006 7:47 pm
Posts: 12
Hi,

I want a resultset return from a findAll() query to always be sorted on a particular column. There's very little documentation on the loader element, but from what I've gathered it should be as easy as 1) defining a query (native or HQL - I've tried both) and 2) referencing it in <loader query-ref="">.

But that doesn't work! I still get the default select statement when calling findAll(). Is there anything else I'm supposed to do other than those 2 steps? The loader element is in the class tag, and I've tried placing the query both in the class tag & after it. Still nothing.

Thanks!

Oh, and can someone tell me how to rate a post??


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 2:10 pm 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
I am not following you completly you want a resultset??? só you want to use normal JDBC? or do you want the result of your findAll which with hibernate
probably is a list ordered???

Can you post some code pelase??

Regards

_________________
Don´t forget to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 2:31 pm 
Newbie

Joined: Wed Jan 25, 2006 7:47 pm
Posts: 12
Sorry - resultset was not an accurate term. I just want the list that's returned from a criteria query.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 2:35 pm 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
You can use Order.asc(...) or Order.desc(....)

Try this
Code:

     List l = session.createCriteria(<Yourclass.class>)
                .setOrder(Order.asc("<property from the class to order by>"))
                .list();




Good luck!

_________________
Don´t forget to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 2:39 pm 
Newbie

Joined: Wed Jan 25, 2006 7:47 pm
Posts: 12
I don't doubt that would work, but I'm using the JDK5 generics pattern recommended by Christian Bauer, so I'd really prefer to implement this ordering in the mapping files. Any more ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 4:02 pm 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
Ahhhhhhhh you are using annotations
try this worked for me:

Code:

@OrderBy (value="<propriedade na classe que está na list> asc")


_________________
Don´t forget to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 9:14 pm 
Newbie

Joined: Wed Jan 25, 2006 7:47 pm
Posts: 12
No, not using annotations... I'm trying to do almost exactly what's in the reference ("16.5. Custom SQL for loading"):

Code:
<sql-query name="person">
    <return alias="pers" class="Person" lock-mode="upgrade"/>
    SELECT NAME AS {pers.name}, ID AS {pers.id}
    FROM PERSON
    WHERE ID=?
    FOR UPDATE
</sql-query>

<class name="Person">
    <id name="id">
        <generator class="increment"/>
    </id>
    <property name="name" not-null="true"/>
    <loader query-ref="person"/>
</class>


But barring any other input, I will override my generic findAll() with your suggestion.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 29, 2006 7:03 am 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
Seems to me this just works for session.load(....) I tried it and worked
but for example using criteria I got another query.

_________________
Don´t forget to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 1:59 pm 
Newbie

Joined: Wed Jan 25, 2006 7:47 pm
Posts: 12
I tried that too & still didn't get the ordering. I'll just use your first suggestion. Thanks a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 2:00 pm 
Newbie

Joined: Wed Jan 25, 2006 7:47 pm
Posts: 12
And now I see how to rate - you have to be logged in first. Duh. :-)


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