Input parameter not recognized when used with custom constructor

Description

JpaRepository:

@Query("SELECT new ReportConfig(rc.uuid, rc.accountId, rc.createDate, rc.modifiedDate, author.id, :userId, author.firstName, author.lastName, rc.title ) FROM ReportConfig rc " +
...
)
List<ReportConfig> findByAccountIdAndUserId(@Param("accountId") Long accountId, @Param("userId") Long userId );

Constructor:

public ReportConfig(
String uuid,
Long accountId,
Date createDate,
Date modifiedDate,
Long ownerId,
Long userId,
String firstName,
String lastName,
String title)
{
// other stuff
}

Exception:

Unable to locate appropriate constructor on class ... Expected arguments are: java.lang.String, long, java.util.Date, java.util.Date, long, java.lang.String, java.lang.String, java.lang.String

As you can see :userId is not recognized as Long input parameter for the constructor.

Clearly the JPQL BNF does permit passing parameters as constructor arguments.

1 2 3 4 5 6 7 constructor_expression ::= NEW constructor_name ( constructor_item {, constructor_item}* ) constructor_item ::= single_valued_path_expression | scalar_expression | aggregate_expression | identification_variable scalar_expression ::= simple_arithmetic_expression | string_primary | enum_primary | datetime_primary | boolean_primary | case_expression | entity_type_expression string_primary ::= state_field_path_expression | string_literal | input_parameter | functions_returning_strings | aggregate_expression | case_expression

 

Environment

None

Status

Assignee

Unassigned

Reporter

Simon Mitev

Labels

None

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Affects versions

5.4.1.Final

Priority

Major
Configure