-->
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: Change the criteria list method
PostPosted: Sun Jun 28, 2009 6:12 pm 
Beginner
Beginner

Joined: Fri Sep 02, 2005 3:42 pm
Posts: 32
Hi all, some times, i would like to create some logic for hibernate before it puts the objects inside the list. For example: let's suppose that this is a hibernate code for put the objects inside the list after the sql.
Code:
for(Object o : list){
  // i would like to put a condition here, java code!!!
   list.add(o);
}


There is anyway to do that out of the box? Or Do i have to implement the criteria interface? I want to do that because sometimes it is easier filter a list with java code than create a sql criteria, at lest before some performance problem.

Thanks,

Alberto


Top
 Profile  
 
 Post subject: Re: Change the criteria list method
PostPosted: Mon Jun 29, 2009 3:35 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Check out result transformers, it might give you what you need.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject: Re: Change the criteria list method
PostPosted: Tue Jun 30, 2009 1:24 pm 
Beginner
Beginner

Joined: Fri Sep 02, 2005 3:42 pm
Posts: 32
nice!!, i will take a look. thanks


Top
 Profile  
 
 Post subject: Re: Change the criteria list method
PostPosted: Tue Jun 30, 2009 3:06 pm 
Beginner
Beginner

Joined: Fri Sep 02, 2005 3:42 pm
Posts: 32
so... resulttransformer wasn't what i was looking for. I can build objects with it, but i can not choose if a object must be inside or not in the list. I know that i should do that with hql or criteria, but sometimes the sql query is a little bit boring and, if the performance enables, i would like to filter my objects with java code.


Top
 Profile  
 
 Post subject: Re: Change the criteria list method
PostPosted: Tue Jun 30, 2009 4:34 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Take a look at DistinctResultTransformer that takes a list of non unique root entities and then pares down the list to a unique result. The list returned from transformList is the list that is ultimately returned.

I still think you want to reduce the results with your query but I still think the transformer is the way to go if you don't.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


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.