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?