I defined my custom dialect for HSQLDB:
public class CustomHSQLDialect extends HSQLDialect {
public CustomHSQLDialect () {
super();
registerFunction("datediffsec", new SQLFunctionTemplate(
StandardBasicTypes.DOUBLE, "cast((?1 - ?2) AS INTERVAL SECOND)"));
}
}
I defined configuration:
hibernate.dialect=custom.dialect.CustomHSQLDialect
Then I'm trying to use it in @Formula:
@Formula("case status when 'ACTIVE' then datediffsec(now(), creationDateTime) when 'CLEARED' then datediffsec(clearedDateTime, creationDateTime) end")
But I catch exception:
Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: DATEDIFFSEC
What I do wrong?
I don't know whether you can create this function as an SQL expression in Hibernate.
But supposing you could, this expression is wrong as far as HSQLDB is concerned.
A correct expression would be like:
(?1 - ?2) INTERVAL SECOND
Also note there is already a TIMESTAMPDIFF function in HSQLDB which allows you to specify seconds as the unit.
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.