和标准的SQL一样,hibernate也可以使用select
但是需要注意的是:
SQL中可以使用
SELECT * FROM T_USER
hibernate中是不可以使用
select * from UserInfo
例如:
hibernate中可以这样使用
String hql = "select person.id from UserInfo user where user.person.id = " + id;
或者
String hql = "from GroupPO po where po.business in (select id from BusinessPO po where po.name = '"+ pgName +"')";
但不能这样使用
String hql = "select * from UserInfo user where user.person.id = " + id;
会抛出异常:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: * near line 1, column 69
本文介绍了在使用Hibernate框架进行数据库操作时,HQL查询语句的使用限制,特别是关于不可使用select *的原因及正确示例。
876

被折叠的 条评论
为什么被折叠?



