1

I have something like the following

@MappedSuperclass public abstract class Foo {
    @Column private String myId;
 }

@Entity public class Bar extends Foo {
}

@Entity public class Baz extends Foo {
}

But I now want to query for all instances of Bar and Baz using myId but my query gets rejected:

org.hibernate.hql.ast.QuerySyntaxException: Foo is not mapped [from Foo foo where foo.myId = :myId]

Paul McKenzie
  • 19,646
  • 25
  • 76
  • 120

1 Answers1

2

Can you query sucessfully on the 2 entitys if you query each one seperately ?

Something like:

Collection<Bar> bars = (Bar) entityManager.createQuery("From Bar bar
    where bar.myId=:myId").setParameter("myId", myId).getResultList();

?

The answer is due to only having tables for concrete classes, if you look here clearer answer to identical question

Community
  • 1
  • 1
Luke
  • 3,481
  • 6
  • 39
  • 63