I am using the JPA criteria API with hibernate 5.4.33 as provider.
Within one query, I am using
cp.construct(SomeClass.class,
SomeEntity_.property,
cb.currentTimestamp());
This is working well with SQLServer and Oracle but not working with Firebird. With Firebird the result is a NullPointerException
(which is nastily caught and rethrown several times), where the root-cause is within class org.hibernate.hql.internal.Namegenerator#generateColumnNames
, where the Type[]
argument contains null
as type of the cb.currentTimestamp()
part of the query.
I am under the impression this might be a bug in hibernate, yet I am not certain.
Has anyone any idea whether I made a mistake here or whether there is a workaround or whether I should file a bug against hibernate?
=== EDIT ===
After some more research, the issue seems to be, that AbstractTransactSQLDialect
registers a function current_timestamp
and with this registration, this function will be made known to be of return type TIMESTAMP
.
No similar function-registration is being done with the InterbaseDialect (which is the base of FirebirdDialect).
Why is this so?
So, for some reasons unknown to me, the FirebirdDialect
in Hibernate 5.4.33 does not define relevant sql functions. This applies to current_timestamp
but also to others (which are defined for SQLServer and Oracle).
The solution is to define the functions yourself if required. This is described here: Registering a SQL function with JPA and Hibernate
In this specific case you have to define the function as follows:
registerFunction(
"current_timestamp",
new NoArgSQLFunction("CURRENT_TIMESTAMP", StandardBasicTypes.TIMESTAMP, false));
I choose the subclass variant, although the above quoted question got an answer, there is a new and better way to do this via configuration. As we actually do use different RDBMS and only one of them requires this workaround, I thought a subclassed dialect would be more appropriate.
Mind the boolean parameter false
, which will omit parenthesis to CURRENT_TIMESTAMP
within the sql (otherwise the sql will be non-parseable to the firebird server).