xiazaiyonde
2011-05-16 09:31
浏览 305
已采纳

sql报错,可是PLSQL Developer里运行没问题 。

org.hibernate.hql.ast.QuerySyntaxException: expecting OPEN, found ',' near line 1, column 14 [select OBJECT,OBJECT_KIND,MAX_CODE,sum(ACOUNT) as ACOUNT,sum(GATHER_MONEY) as GATHER_MONEY,to_char(DATE_FROM,'yyyy-mm-dd') as DATE_FROM,to_char(DATE_TO,'yyyy-mm-dd') as DATE_TO,IT_DESC,REMARK,SUN_NUMBER,EXPRESS,to_char(SUBMIT_TIME,'yyyy-mm') as SUBMIT_TIME from SDB_CON_SUBMIT where 1=1 group by SUBMIT_TIME,OBJECT,OBJECT_KIND,MAX_CODE,DATE_FROM,DATE_TO,IT_DESC,REMARK,SUN_NUMBER,EXPRESS ORDER BY SUBMIT_TIME ASC]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:284)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:80)
..........

dao的执行:
String sql = "select OBJECT,OBJECT_KIND,MAX_CODE,sum(ACOUNT) as ACOUNT," +
"sum(GATHER_MONEY) as GATHER_MONEY," +
"to_char(DATE_FROM,'yyyy-mm-dd') as DATE_FROM," +
"to_char(DATE_TO,'yyyy-mm-dd') as DATE_TO,IT_DESC,REMARK,SUN_NUMBER,EXPRESS," +
"to_char(SUBMIT_TIME,'yyyy-mm') as SUBMIT_TIME " +
"from SDB_CON_SUBMIT where 1=1 " ;

    if(null!=supplierID){
        sql+= "and FIRM_ID= "+supplierID+" ";
    }

    if(conObject!=null){
        sql+= "and object= "+""+conObject+" ";
    }

    sql +="group by SUBMIT_TIME,OBJECT,OBJECT_KIND,MAX_CODE,DATE_FROM,DATE_TO,IT_DESC,REMARK,SUN_NUMBER,EXPRESS ";
    sql +="ORDER BY SUBMIT_TIME ASC";

Query query = getSession().createQuery(sql);

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

5条回答 默认 最新

  • fmjsjx 2011-05-16 09:59
    最佳回答

    [quote]
    Query query = getSession().createQuery(sql);
    [/quote]
    没记错的话这行代码生成的是HQL的Query,你用SQL语句生成HQL查询当然会错,记得Hibernate也有执行SQLQuery的,好像是session.createSQLQuery(sql),不过从来没用过,具体还是参考官方文档的好。

    评论
    解决 无用
    打赏 举报
查看更多回答(4条)

相关推荐 更多相似问题