【问题标题】:Insert query not executing in Hibernate but in Oracle插入查询不在 Hibernate 中执行,而是在 Oracle 中执行
【发布时间】:2014-03-29 10:19:38
【问题描述】:

我做了一个在 Oracle 中运行但在 Hibernate 中出错的插入查询。

查询:

insert into tmptable
  (dcol1, ncol1, ncol2)
  select TRUNC(hie.timestamp), min(hie.eventid), count(1)
    from eventtable hie
   where hie.eventid >= 123
     and hie.eventtype = 'NEW'
     and hie.key like 'SYS_%'
     and hie.timestamp between trunc(sysdate - 3) and
         trunc(sysdate) + to_dsinterval('00 23:59:59')
   group by TRUNC(hie.timestamp)
   order by TRUNC(hie.timestamp);

从 Spring MVC + Hibernate 运行时,出现以下错误:

HTTP Status 500 - Request processing failed; 
nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: 1 near line 1, column 113 [insert into tmp$genutil .....]

以下是插入数据的代码:

/* TMP_TABLE_INSERT member variable has above Insert query */
Query query = getSession().createQuery(TMP_TABLE_INSERT);
int result = query.executeUpdate();
System.out.println("Rows affected: " + result);

你能建议这里出了什么问题吗?

【问题讨论】:

    标签: java spring hibernate


    【解决方案1】:

    createQuery 用于创建 HQL 查询,它是 Hibernate 的自定义查询语言,类似于 SQL。

    你想要createSQLQuery

    【讨论】:

    • 感谢您的帮助:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-03
    • 2016-08-29
    • 2022-07-05
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    相关资源
    最近更新 更多