我得到过滤的“培训师”实体,但集合(trainedMonkeys)没有被过滤。'trainedMonkeys' 变量保存所有 'Monkey' 对象,而不是仅保存具有 'isThumb = true' 的对象。
有人可以检查我使用的以下标准是否正确?
@SuppressWarnings("unchecked")
public List<Trainer> listTrainers() {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Trainer.class)
.createAlias("trainedMonkeys", "tm")
.add(Restrictions.eq("tm.isThumb", true))
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
培训师.java
public class Trainer {
private Long trainerId;
private String trainerName;
public List<Monkey> trainedMonkeys;
猴子.java
public class Monkey {
private Long id;
private String monkeyName;
private boolean isThumb;
我在控制器中执行下面的代码,
for (Trainer trainer : trainerList){
System.err.println("<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>");
System.err.println("Trainer ID*****"+trainer.getTrainerId());
System.err.println("Trainer Name******"+trainer.getTrainerName());
monkeyList = trainer.getTrainedMonkeys();
for (Monkey monkey : monkeyList){
System.err.println("Monkey ID*****"+monkey.getId());
System.err.println("Monkey Name*****"+monkey.getMonkeyName());
}
System.err.println("<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>");
}
并且输出如下(Monkey_2 和 Monkey_6 是唯一应该存在的对象,因为只有它们满足条件)请帮助,
<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>
Trainer ID*****88
Trainer Name******TrainerSachin
Monkey ID*****87
Monkey Name*****Monkey_1
Monkey ID*****88
Monkey Name*****Monkey_2
Monkey ID*****89
Monkey Name*****Monkey_3
<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>
Trainer ID*****89
Trainer Name******TrainerVinod
Monkey ID*****90
Monkey Name*****Monkey_5
Monkey ID*****91
Monkey Name*****Monkey_6
Monkey ID*****92
Monkey Name*****Monkey_7
<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>