Paul McKenzie
Paul McKenzie

Reputation: 20096

Query on attribute from @MappedSuperclass

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]

Upvotes: 1

Views: 1241

Answers (1)

Luke
Luke

Reputation: 3541

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

Upvotes: 2

Related Questions