We're updating the issue view to help you get more done. 

JPA SQL function with no arguments can only be called if we provide a comma

Description

Assuming that we want to call the NOW() database function from an entity query.

If we write the query like this:

1 2 3 4 5 6 Date now = entityManager.createQuery( "select FUNCTION('now') " + "from Event " + "where id = :id", Date.class) .setParameter( "id", 1L ) .getSingleResult();

We get the following exception thrown:

1 java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: expecting COMMA, found ')' near line 1, column 22 [select FUNCTION('now') from org.hibernate.test.sql.function.JpaFunctionTest$Event where id = :id]

If we provide a comma:

1 2 3 4 5 6 Date now = entityManager.createQuery( "select FUNCTION('now',) " + "from Event " + "where id = :id", Date.class) .setParameter( "id", 1L ) .getSingleResult();

It works fine.

However, according to JPA specs, the BNF is:

1 function_invocation::= FUNCTION(function_name {, function_arg}*)

Environment

None

Status

Assignee

Vlad Mihalcea

Reporter

Vlad Mihalcea

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Components

Affects versions

5.2.4

Priority

Major