0

我正在使用这个例子: http ://www.mkyong.com/hibernate/hibernate-query-examples-hql/

并尝试以这种方式删除:

String qhl = "delete from logs  where dateTtime >= current_date - interval '1 month'";
Query query = session.createQuery(hql);
return query.executeUpdate();

但我得到这个错误:

ERROR: line 1:61: unexpected token: '1 month'
Mai 23, 2014 3:07:22 PM org.hibernate.hql.internal.ast.ErrorCounter reportError
ERROR: line 1:61: unexpected token: '1 month'
line 1:61: unexpected token: '1 month'
    at org.hibernate.hql.internal.antlr.HqlBaseParser.identPrimary(HqlBaseParser.java:4016)
    at org.hibernate.hql.internal.antlr.HqlBaseParser.primaryExpression(HqlBaseParser.java:859)
    at org.hibernate.hql.internal.antlr.HqlBaseParser.atom(HqlBaseParser.java:3390)
    at org.hibernate.hql.internal.antlr.HqlBaseParser.unaryExpression(HqlBaseParser.java:3168)
...

尝试此操作时:

String qhl = "delete from logs where dateTtime >= ( select cast(date_trunc('month', current_date) as date) )";

错误是:

logs is not mapped [delete from logs where dateTtime >= ( select cast(date_trunc('month', current_date) as date) )]

我做错了什么?

4

1 回答 1

1

它不是有效的 hql,只需使用hibernate 的本机查询功能,用于供应商特定的数据库功能。

于 2014-05-23T19:18:21.007 回答