我试图用Hibernate 3和Oracle 10编写这个查询。
from Alert alert where alert.expiration > current_date() order by alert.priority,alert.updated,alert.name
它正在创建这样的sql –
Hibernate: select alert0_.ANNOUNCEMENTS_ID as ANNOUNCE1_1_,alert0_.ANNOUNCEMENT S_NAME as ANNOUNCE2_1_,alert0_.ANNOUNCEMENTS_PRIORITY as ANNOUNCE3_1_,alert0_. ANNOUNCEMENTS_EXPIRATION as ANNOUNCE4_1_,alert0_.ANNOUNCEMENTS_UPDATE_DATE as A NNOUNCE5_1_ from NYC311_ANNOUNCEMENTS alert0_ where (alert0_.ANNOUNCEMENTS_EXPIR ATION>current_date()) order by alert0_.ANNOUNCEMENTS_PRIORITY,alert0_.ANNOUNC EMENTS_UPDATE_DATE,alert0_.ANNOUNCEMENTS_NAME
当有明显完美平衡的圆括号时,我会收到所有这些古怪的错误,如“缺少右括号”。
为什么Oracle在这方面出局了?有没有更好的方式来编写我的HQL查询?
不应该
原文链接:https://www.f2er.com/oracle/205969.htmlcurrent_date
? hibernate会把它翻译成正确的方言
我没有发现一个真正的“Hibernate会把这个翻译成这个”的参考文档,但一般来说,表达式可以在Hibernate Doc for HQL Expressions for Hibernate 4.3中找到
那么有一个规范:Java Persistence API 2.0 (JPA),它定义了Java持久性查询语言(JPQL)的表达式及其含义。 for current_date:
4.6.17.2.3 Datetime Functions functions_returning_datetime:= CURRENT_DATE | CURRENT_TIME | CURRENT_TIMESTAMP The datetime functions return the value of current date,time,and timestamp on the database server.