-->
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: Help for a criteria query
PostPosted: Sat Jan 29, 2011 10:40 am 
Newbie

Joined: Sun Oct 18, 2009 8:27 am
Posts: 3
Hello every body

I have a problem with criteria, i'm not able to do what i need…

My db is very simple: a table Player(type) with one-to-many with the table PlayerData(player, type)

I have a map, associating some player types with some datatypes, for example {PT1:[DT11,DT12], PT2:[DT21]}
And i try to generate the corresponding criteria, which must be something like that:

Code:
select * from PlayerData where
    (player.type = PT1 and type in (DT11, DT12))
    or (player.type = PT2 and type in (DT21))


But no way for the moment… The problem is that to generate a "player.playerType = ... and dataType in (...)", i need a createCriteria() because of the association, but to "or"-ed all, i need a criterion, and not a criteria…

Here is my not functionnal code for the moment:
Code:
final Criteria criteria = this.getSession().createCriteria(PlayerData.class);
Criterion or = Restrictions.conjunction();
for (final Entry<PlayerType, Collection<DataType>> type : types.entrySet()) {
    or.add(Restrictions.and(
        Restrictions.in("player.type", type.getValue()),
        Restrictions.eq("type", type.getKey()))
    );
}
criteria.add(or);
criteria.list();

This code is not functionnal because of the "player.type", association is not resolved in Criterion.
And if I made a Criteria to resolve the association, conjunction claims only Criterion…

Anybody could help me?


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.