简体   繁体   中英

how to add day to date in ejbql

I am trying to achieve dateadd in my EJB query. I tried something like this but it doesn't work:

select t.date + 1 from Table t

Once I tried executing that code, this exception comes out:

org.hibernate.exception.SQLGrammarException: ERROR: operator does not exist: timestamp without time zone + integer Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. Position: 93

I also tried casting 1 to date and interval but the query result would only be null. I just wonder, is it really possible to add days in a given date in an EJB query

There is no support for date arithmetic and also no possibility to extract day from date in EJBQL, and also not in JPQL.

Depending about JPA provider (Hibernate, EclipseLink etc.) there can be useful vendor specific extensions and possibility to call database functions. For example with EclipseLink FUNC can be used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM