-->
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.  [ 1 post ] 
Author Message
 Post subject: criteria query initializes assoziations with search criteria
PostPosted: Sun Mar 31, 2013 7:13 pm 
Newbie

Joined: Sun Nov 30, 2008 8:54 am
Posts: 4
Hello,
i have a problem with Criteria Queries.

I have 3 entities:
location (1:n) locationteammapping (m:1) team

I want to get all locations with a specific locationname or teamname.

For each returned location i want to get all locationteammappings.
But location.getLocationteammappings() only returns the mappings where the teamname is matching.

Example:
Loc A - Team X
Loc A - Team Y
Loc C - Team Z

If i search for "A" the query will return "Loc A". "Loc A".getLocationteammappings() returns X and Y.

If i search for "X" the query will return "Loc A". "Loc A".getLocationteammappings() only returns X. Y is missing.

It seems that the collection is already initialized with the query result. How can i avoid this?




My Query:

Criteria c = getSession().createCriteria(Location.class);
c.createAlias("locationteammapping","m", CriteriaSpecification.LEFT_JOIN);
c.createAlias("m.team", "t", CriteriaSpecification.LEFT_JOIN);

c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
c.setFetchMode("locationteammapping",FetchMode.SELECT);

Disjunction dis = Restrictions.disjunction();
c.add(dis);

dis.add(Restrictions.ilike("locationname", "A", MatchMode.ANYWHERE))
dis.add(Restrictions.ilike("t.teamname", "A", MatchMode.ANYWHERE))

Thanks
Andi


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.