Search code examples
jpajpqlhibernateexception

JPQL: InnerSelect causes PersistenceException (HibernateException: Errors in named queries)


I try to use an inner select, but get only the exception "HibernateException: Errors in named queries"

The both JPA entities:

public class A implements Serializable {
   @Id
   @Column(nullable = false)
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Long id;
}

public class B implements Serializable {
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Long id;

   @JoinColumn(name = "FK_A_ID", nullable = true)
   @ManyToOne
   private A a;
}

This query causes the exception:

SELECT a FROM A a WHERE a.id NOT IN (SELECT b.a.id FROM B b)

But this causes no exception:

SELECT a FROM A a WHERE a.id NOT IN (1, 2, 3)

Any idea what is wrong? Thanks a lot...


Solution

  • The reason was visible on other output:

    QuerySyntaxException: "Tablename is not mapped"
    

    This error was logged and not available in the exception.