我有实体 Team、Game 和 TeamInGame。要选择按上一场比赛排序的球队,我使用:
Query query = em.createQuery("select tg.team, max(tg.game.gameDate) as maxDate" +
" from TeamInGame tg" +
" group by tg.team" +
" order by maxDate desc");
return Lists.transform(query.getResultList(), new Function<Object[], Team>() {
@Override
public Team apply(Object[] input) {
return (Team) input[0];
}
});
有没有办法摆脱这种转变?此查询不起作用:
return em.createQuery("select tg.team, max(tg.game.gameDate) as maxDate" +
" from TeamInGame tg" +
" group by tg.team" +
" order by maxDate desc", Team.class).getResultList();