我有查询从多个实体返回数据
@Override
public List<PlayerDetails> testPlayerQuerry() {
return copyTest(em.createNativeQuery("select player_name, pg.player_game_score, g.game_description from player p\n"
+ "join Player_Game pg on p.player_id = pg.fk_player_id\n"
+ "join Game g on pg.fk_game_id = g.game_id\n"
+ "where g.game_id = 2").getResultList());
从查询中检索从一个实体返回数据的数据相对简单,可以像这样完成
private List<PlayerDetails> copyPlayersToDetails(List< Player> players) {
List<PlayerDetails> list = new ArrayList<PlayerDetails>();
Iterator i = players.iterator();
while (i.hasNext()) {
Player player = (Player) i.next();
PlayerDetails details = new PlayerDetails(player.getPlayerId(),
player.getPlayerName(), player.getPlayerRating());
list.add(details);
}
return list;
}
问题是当查询存储来自多个实体的数据时如何执行此操作?