Hibernate的HQL问题

来源:百度知道 编辑:UC知道 时间:2024/06/05 13:01:37
// 信息审核员,系统管理员查看未通过的加盟申请
//查初审结果为空的数据
public List<Shopjoinapply[]> findUnpassShopjoinapply() {
List<Shopjoinapply[]> shopjoinapplyList = null;
String hql = "select shopjoinapplyid,shopjoinapplycode,fullname,shoppropid,tradeid,business,firstjudgeresult from Shopjoinapply where firstjudgeresult =?";
Session session = this.getSession();
Query query = session.createQuery(hql);
query.setString(0, null);
shopjoinapplyList = query.list();
return shopjoinapplyList;
}

2008-12-22 19:09:56 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet default threw exception
java.sql.SQLException: ORA-00904: "SHOPJOINAP0_"."TRADE": 标识符无效

Hibernate不能这么查还是哪里错了??????

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)

query.setString(0, null);
java code里的null和sql 语句里的NULL又不一样,这么用肯定错

HQL语句格式其实跟SQL基本一样,SQL对了的话,HQL就错不到哪去?你应该这么写吧:
String hql = "select shopjoinapplyid,shopjoinapplycode,fullname,shoppropid,tradeid,business,firstjudgeresult from Shopjoinapply where firstjudgeresult IS NULL";
list = session.createQuery(hql).list();

这样写
String hql = "SELECT s.shopjoinapplyid,s.shopjoinapplycode,s.fullname,s.shoppropid,s.tradeid,s.business,s.firstjudgeresult FROM Shopjoinapply AS s WHERE s.firstjudgeresult =?";
试一下,HQL里面通过类查询要使用别名

二楼正确