0

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?

Jonathan
  • 2,698
  • 24
  • 37
  • It sounds like you should report a bug to the Hibernate project instead of asking why this bug exists in Hibernate. As a workaround, you can probably subclass the dialect and register the necessary function yourself, but given you have provided no [mre] and did not specify the version of Hibernate and Firebird, that is hard to verify. – Mark Rotteveel Feb 21 '22 at 18:04
  • Probably you are right. In the past, I have often noted non-constructive responses form the hibernate/red hat communities and learned to rely on other sources of information if in trouble. As I was in no mood to get pointed out, that I am unworthy/too stupid to use hibernate, I thought, I would rather try my luck here (and a bit hastily as I got my answer all by myself with a little more effort) – Jonathan Feb 21 '22 at 18:23
  • Last year I contributed an improved dialect for Firebird to Hibernate 6 and found them pretty responsive. Unfortunately, Hibernate 6 is still a while away. I'll see if I can contribute some minor improvements to the current version(s). I find it curious that this doesn't work out-of-the-box. – Mark Rotteveel Feb 21 '22 at 19:01

1 Answers1

1

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).

Jonathan
  • 2,698
  • 24
  • 37