碰到问题就积累下:
hibernate查询时候写了下面sql语句:
public GameListInfoDTO getGameInfoByGameId(String gameId){
String hql ="select new com.ibaiyun.dto.GameListInfoDTO(g.id,g.time,g.endtime,t.name,t.minBet,"
+ "count(p.recordid),t.paywin) "
+ "from Gamerecord g,Tableboard t,Playerrecord p "
+ "where t.id = g.tableid and g.time = p.time and g.id=? group by g.id";
Query query = sessionFactory.getCurrentSession().createQuery(hql);
query.setInteger(0, Integer.parseInt(gameId));
return (GameListInfoDTO) query.uniqueResult();
}
一开始不知道怎么返回这些零零散散得到的属性数据,因为在不同表里,后来网上找了,就自己写个实体类封装,最初是这样写的,一开始连实体类属性字段都没和sql语句查询的字段对上,纠结了挺久:
public class GameListInfoDTO {
private int id;
private Date time;
private Date endtime;
private String name;
private int minBet;
private String recordid;
private short paywin;
public GameListInfoDTO(int id, Date time, Date endtime, String name,
int minBet, Long recordid, short paywin) {
super();
this.id = id;
this.time = time;
this.endtime = endtime;
this.name = name;
this.minBet = minBet;
this.recordid = recordid;
this.paywin = paywin;
}
这样写后,还是报属性字段对不上,再在网上查了count得到的结果集什么类型的,后来改为Long之后就运行正常了:
private Long recordid;
有问题就记录了一下