QueryException when using CriteriaBuilder.function()

Description

I was trying to do a simple select using JPA:

So, I give it a try:

And this gives me back a QueryException:

Then, I tried to cast it:

(I have tried to cast it as String and Long. Casting to Integer results in the same exception as above.)

And then I get another QueryException:

What am I doing wrong?
Is there something I can do to solve this issue on the "user" side?

I noticed this error occurs with the following functions:

  • CHARSET

  • CONNECTION_ID

  • CONCAT_WS

  • CONV

  • DATABASE

  • POW

  • POWER

  • FORMAT

  • REPEAT

  • REPLACE

  • SUBSTR

  • USER

  • UUID

P.S.: I tried the above query using EclipseLink and it works fine.
P.S.2: POW and POWER don't work and are the same function. But in the SUBSTR and SUBSTRING pair, only the first don't work.

(As reported in https://stackoverflow.com/questions/45725573/queryexception-on-hibernate-when-using-criteriabuilder-function?noredirect=1#comment78415129_45725573)

Environment

Hibernate 5.2.10
MySQL 5.7.18 (localhost)
MySQL-connector 5.1.42 (driver)
Windows 10
Java 1.8.0_131-b11
Dialect: org.hibernate.dialect.MySQLDialect
Database: MySQL Default Examples (schema world)

Assignee

Unassigned

Reporter

Miguel Koscianski Vidal

Fix versions

None

backPortable

None

Suitable for new contributors

Yes, likely

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure