Got IllegalArgumentException after hibernat upgrade

We are upgrading hibernate from 5.X to 6.3.1.Final. The following code was working fine with hibernate 5.x but got IllegalArgumentException with 6.X version. We have tested with 6.1.7.Final and 6.3.1.Final.

Full Exception:
java.lang.IllegalArgumentException: org.hibernate.query.sqm.produce.function.FunctionArgumentException: Parameter 2 of function ‘timestampdiff()’ has type ‘TEMPORAL’, but argument is of type ‘java.sql.Timestamp’
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:143)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:167)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:173

Code:

  private List<CusRawCmfDataEntity> getNotRxedRawCmfData(
      OtaPathId otaPathId,
      long startTime,
      long endTime,
      List<Priority> priorities,
      List<String> origAddrs) {
    if (endTime < startTime) {
      return Collections.emptyList();
    }

    long queryStartTime = System.nanoTime();

    if (CollectionUtil.isNullOrEmpty(priorities)) {
      priorities = Arrays.asList(Priority.p1ToP4Values());
    }

    StringBuilder query = new StringBuilder();

    // Initial part of the query based on the database type
    query.append("SELECT r FROM CusRawCmfData r WHERE r.id IN ( ");
    query.append("SELECT u.id FROM CusMetaData u LEFT JOIN CmfData m ON (");
    query.append("u.otaPathId=m.otaPathId AND u.originator=m.originator AND ");
    query.append("u.msgNum=m.msgNumber AND u.msgType=m.msgType AND u.toi=m.toi ");

    // Time comparison based on the database type
    if (dmeAppSettings.isPostgresqlDatabase()) {
      query.append(
          "AND ABS(date_part('epoch', u.timeOfEntry) - date_part('epoch', m.rptTimeOfEntry)) < 5) ");
    } else if (dmeAppSettings.isH2Database()) {
      query.append("AND DATEDIFF(SECOND, u.timeOfEntry, m.rptTimeOfEntry) < 5) ");
    } else {
      query.append("AND u.timeOfEntry=m.rptTimeOfEntry) ");
    }

    // Continuing common part of the query
    query.append(
        "WHERE u.otaPathId = :cibId AND u.timeOfExit BETWEEN :startTime AND :endTime AND u.priority IN :priorities ");

    // If originator addresses are not empty
    if (!CollectionUtil.isNullOrEmpty(origAddrs)) {
      query.append("AND u.originator IN :origAddrs ");
    }

    query.append("AND m.id IS NULL)");

    TypedQuery<CusRawCmfDataEntity> q =
        entityManager
            .createQuery(query.toString(), CusRawCmfDataEntity.class)
            .setParameter("startTime", startTime)
            .setParameter("endTime", endTime)
            .setParameter("cibId", otaPathId)
            .setParameter("priorities", priorities);
    if (!CollectionUtil.isNullOrEmpty(origAddrs)) {
      q.setParameter("origAddrs", origAddrs);
    }
    List<CusRawCmfDataEntity> result = q.getResultList();

    log.debug("getNotRxedRawCmfData took "
        + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - queryStartTime)
        + " ms.");
    return result;
  }

Time fields are long type and mapped to SQL timestamp.

  @NotNull
  @Convert(converter = LongToTimestampConverter.class)
  @Column(name = "tmEn")
  protected long timeOfEntry;

I got the error when testing with H2 database. Function “datediff” triggered the exception.
How to fix this issue?

This looks like a bug. Please create an issue in the issue tracker(https://hibernate.atlassian.net) with a test case(https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) that reproduces the issue.