public List<TrainUser> findByTrainPlanRegist(Long planId) {
// Criteria criteria = this.getSession().createCriteria(TrainUser.class);
// criteria.createAlias("appUser", "appUser");
// criteria.createAlias("trainPlan", "trainPlan");
// criteria.add(Restrictions.eq("trainPlan.id", planId)).add(Restrictions.eq("regist", TrainUser.REGIST));
// return criteria.list();
String hql="select tu from TrainUser tu JOIN fetch tu.appUser tuau JOIN fetch tu.trainPlan tutp where tu.trainPlan.id = ? and tu.regist = ?";
Query query = this.getSession().createQuery(hql);
query.setParameter(0, planId);
query.setParameter(1, TrainUser.REGIST);
List list = query.list();
// Criteria criteria = this.getSession().createCriteria(TrainUser.class);
// criteria.createAlias("appUser", "appUser");
// criteria.createAlias("trainPlan", "trainPlan");
// criteria.add(Restrictions.eq("trainPlan.id", planId)).add(Restrictions.eq("regist", TrainUser.REGIST));
// return criteria.list();
String hql="select tu from TrainUser tu JOIN fetch tu.appUser tuau JOIN fetch tu.trainPlan tutp where tu.trainPlan.id = ? and tu.regist = ?";
Query query = this.getSession().createQuery(hql);
query.setParameter(0, planId);
query.setParameter(1, TrainUser.REGIST);
List list = query.list();
return list;
join fetch 才可以将对象中的对象属性插入对象