-->
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.  [ 3 posts ] 
Author Message
 Post subject: Association - Applying Criteria to Persistent Collection
PostPosted: Tue Aug 30, 2005 10:46 pm 
Newbie

Joined: Tue Aug 30, 2005 10:01 pm
Posts: 2
Good day,

I hv created Project and ProjectDtl with one-to-many relationship.

Each call to oProject.getDetails() will return me a full list of the associated details Currently I hv to use a filter to retrieve the filtered details.

I tried the following code and it still return all the details when I call oProject.getDetails().

Code:
criteria = createCriteria();
         
         criteria.add(Expression.eq(Project.PROP_PROJECTNBR, id));
         
         // Append search criteria for details, sorting order, filter string
         criteriaDetail = criteria.createCriteria(ProjectDtl.PROP_DETAILS, ProjectDtl.PROP_DETAILS);
         
         if (stFilterDetails != null && stFilterDetails.length() > 0)
            criteriaDetail.add(Expression.ilike(ProjectDtl.PROP_PRRFNBR, stFilterDetails, MatchMode.START));
         
         if ((searchCategoryDetails != null && searchCategoryDetails.length() > 0) &&
            (searchStringDetails != null && searchStringDetails.length() > 0))
               criteriaDetail.add(Expression.ilike(searchCategoryDetails, searchStringDetails, MatchMode.START));
         
         criteriaDetail.setFirstResult(startRowDetails);
         criteriaDetail.setMaxResults(endRowDetails);
         
         list = criteria.list();


I saw in the net that I can use the following code to get the filtered collection.

Code:
list = criteriaDetail.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).list();


Instead of return a list of Project, the code will return a Hashmap.

Is there any way to apply a criteria object to filter persistent collection and return a list of Project ?




Additional info :
Hibernate version: 3
Name and version of the database you are using: DB2 v8.1


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 3:50 pm 
Newbie

Joined: Thu Nov 10, 2005 12:35 pm
Posts: 6
I don't know if this will help you or not, but I ran into the same problem.

I ended up doing something like this.

[code]list = criteriaDetail.setResultTransformer(Project.class).list();
[/code]

This executed the query and populated the parent class.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 4:30 pm 
Newbie

Joined: Thu Nov 10, 2005 12:35 pm
Posts: 6
Sorry. Typo.

It should be

criteriaDetail.setResultTransformer(new AliasToBeanResultTransformer(Project.class));


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