JPA 2.2 @NamedQuery not recognized in EntityManager createNamedQuery
Answered
Maven: jakarta.persistence:jakarta.persistence-api:2.2.3
@Repeatable(NamedQueries.class)
@Target(TYPE)
@Retention(RUNTIME)
public @interface NamedQuer
JPA 2.2 @NamedQuery not recognized in EntityManager createNamedQuery

@NamedQuery(name = "Employee.getAll",
query = "SELECT u from Employee u order by u.employeeId")
@NamedQuery(name = "Employee.getAllStartFrom",
query = "SELECT u from Employee u where u.employeeId between :startId AND :fromId order by u.employeeId")
//@NamedQueries({
// @NamedQuery(name = "Employee.getAll",
// query = "SELECT u from Employee u order by u.employeeId"),
// @NamedQuery(name = "Employee.getAllStartFrom",
// query = "SELECT u from Employee u where u.employeeId between :startId AND :fromId order by u.employeeId")
//})
public class Employee implements Serializable {
entityManager.createNamedQuery("Employee.getAllStartFrom", Employee.class)
.setParameter("startId", start)
.setParameter("fromId", from);
Please sign in to leave a comment.
Could you please provide the exception, generated in the idea.log (Help | Show Log In ..)? You can create a support rewuest and attach the whole log fole.
Hi @Liubov Melnikova
As the originator didn't respond I'll because I'm facing the same issue.
It's related to the new @Repeatable(NamedQueries.class) introduced in JPA 2.2 where you don't need to enclose yours @NamedQuery into an @NamedQueries when you have more than one.
It works fine when run, but we have an underline red line bellow the namedQuery and it is not possible to use the Ctrl+Click to got to the declaration.
My IDE Version:
IntelliJ IDEA 2019.3.3 (Ultimate Edition)
Build #IU-193.6494.35, built on February 11, 2020
Runtime version: 11.0.5+10-b520.38 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 5.4.19-100.fc30.x86_64
Thanks
Hello,
There is related issue on YouTrack: https://youtrack.jetbrains.com/issue/IDEA-215287
Please follow it for updates.