Вставить запрос, выполняемый не в Hibernate, а в Oracle

Я сделал запрос на вставку, который выполняется в 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);

Не могли бы вы подсказать, что здесь происходит не так?


person Sandeep    schedule 29.03.2014    source источник


Ответы (1)


createQuery используется для создания запроса HQL, который представляет собой собственный язык запросов Hibernate, аналогичный SQL.

Вы хотите createSQLQuery.

person takteek    schedule 29.03.2014
comment
Спасибо за вашу помощь :) - person Sandeep; 29.03.2014