我有實體Team,Game和TeamInGame。要選擇他們上一場比賽所使用的球隊:只使用JPQL選擇列的子集對象
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();
當您說「...此查詢不起作用...」時,您是否遇到異常?它是什麼? – sharakan