hibernate 查询出错-
hibernate 查询语句:
userid 字段参照的是 UserInfo 表里面的主键,在我发hql语句就报错了,求解~
@Override
public List<Address> getallAddress(int userid) {
System.out.println(" ---get all address ---");
Query query = sessionFactory.openSession().createQuery(
"select * from t_Address where userid=?");
query.setParameter(0, userid);
List<Address> list = query.list();
return list;
}
错误:
Struts Problem Report
Struts has detected an unhandled exception:
Messages: unexpected token: * near line 1, column 8 [select * from t_Address where userid=?]
File: org/hibernate/hql/ast/
QuerySyntaxException.java
Line number: 54
--------------------------------------------------------------------------------
Stacktraces
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: * near line 1, column 8 [select * from t_Address where userid=?]
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:284)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136
------解决方案--------------------而且不支持 * ,你直接写的sql ,当然不行
应该 SELECT o FROM className o WHERE o.xx = :xx
o,其实相当于是一个对象,className 是一类。
------解决方案--------------------用混淆了不啊