Hibernate的find的一个易混淆小点

两种写法

Query query = session.createQuery("from SuggestForCoach sfc where sfc.sugCoachFlag = :sugCoachFlag and sfc.sugCoach = :sugCoach order by sfc.sugCoachTime desc");
query.setParameter("sugCoachFlag", 0);
query.setParameter("sugCoach", coach);
//跟第一种不一样的是:这里不可以加别名sfc,sug_for_Coach是数据库中的字段名字
Query query = session.createQuery("from SuggestForCoach  where sugCoachFlag = :sugCoachFlag and sug_for_Coach = :sugCoach order by sugCoachTime desc");

query.setParameter("sugCoachFlag", 0);
query.setParameter("sugCoach", coach.getCoachId());

你可能感兴趣的:(Hibernate)