hibernate关联查询出现问题
本帖最后由 mvpanswer7 于 2014-03-28 11:41:27 编辑
关联查询的时候,创建别名这句.createAlias("City", "c")总是报错,查了网上关联查询的例子,基本上都有这句啊,不懂了,求问啊TUT
代码如下:
public List<Rss> getRssByCity(String cityname) {
// TODO Auto-generated method stub
Session session = sessionFactory.getCurrentSession();
List<Rss> list = new ArrayList<Rss>();
//通过 Hibernate 的Criteria查询
if (!(null== cityname && "".equals(cityname)))
{
Criteria criteria = session.createCriteria(Rss.class)
.add(Restrictions.eq("cityname", new String())
.createAlias("City", "c")//这句总是报错啊
.add(Restrictions.ge("c.city_id", new Long(10))));
list = criteria.list();
}
Iterator<Rss> iterator = list.iterator();
while(iterator.hasNext()){
Rss rss = (Rss)iterator.next();
/* System.out.println(rss.getCityname());
System.out.println(rss.getRssid());
System.out.println(rss.getRssname());
System.out.println(rss.getRssurl());
*/
}
if(list != null && list.size() > 0)
{
return list;
}
return null;
}
------解决方案--------------------createAlias("City", "c") City是实体类 加上双引号干什么?