自我加入休眠

时间:2013-06-12 08:11:08

标签: java mysql hibernate

我收到以下异常:

HTTP Status 500 - Request processing failed;
nested exception is org.springframework.orm.hibernate3.HibernateQueryException: expecting OPEN, found '.' near line 1, column 35 [from in.bets.crm.model.User u1, in.bets.crm.model.User u2 where u1.manager is not null and u2.manager.id = u1.id];
nested exception is org.hibernate.hql.ast.QuerySyntaxException: expecting OPEN, found '.' near line 1, column 35 [from in.bets.crm.model.User u1, in.bets.crm.model.User u2 where u1.manager is not null and u2.manager.id = u1.id]

我编写的查询如下:

users=hibernateTemplate.find("from User u1, User u2 where u1.manager is not null and u2.manager.id = u1.id");

请帮助解决此错误。 谢谢

1 个答案:

答案 0 :(得分:0)

试试这个:(只需添加选择和加入关键字!)

users = hibernateTemplate.find(“select u from User u inner join User m,其中u.manager不为null,u.manager.id = m.id”);