This is not built into Hibernate, so you will need some kind of custom function.
The JDBC standard includes the escape function {fn TIMESTAMPADD( SQL_TSI_SECOND, secs, timestamp)} , which must be translated into the correct SQL for the target database, but not all JDBC implementations provide it. Therefore, there is a chance that you can add the custom standard standard function JDBCEscapeFunction in the Hibernate dialog box to get the desired result.
If you don't have this, you will need to figure out what a particular implementation of a particular database is, and there is a lot of variability here. For instance:
Oracle: (timestamp + secs/86400)
SQLServer: DATEADD(ss,secs,timestamp)
DB2: (timestamp + secs SECONDS)
MySQL: DATE_ADD(timestamp, INTERVAL secs SECONDS)
Once you know this, you can use the correct expression as an SQL criterion.
The fact that date manipulation is not standardized in the dialect and not fully implemented in many JDBC means that what you are trying to do will be very difficult to write in a neutral database mode.
source share