Abhishek Nayak
Abhishek Nayak

Reputation: 3748

spring data jpa select query for super class field

I have a super class(which is not a @Entity or @MappedSuperClass) and sub-class entty class like:

Class A {
   @ElementCollection
   protected Collection<SomeEntity> someEntities;

// getter and setter
}

And

@Entity
Class B extends A {        
  private String name; 
 //getter and setter
}

I have written custom query to select name and someEntities like:

@Query ("select b.name, b.someEntities from B b")

It throws a exception in runtime saying unrecognized field someEntities.

Any solution were I did mistakes?

Upvotes: 2

Views: 1073

Answers (1)

Predrag Maric
Predrag Maric

Reputation: 24433

If your super class is not @Entity or @MappedSuperclass (any reason for this?), then simply any field declared in it is not persistent, is not known to hibernate, and can not be used in queries. If you provide a use case, it could help us providing an alternative.

Upvotes: 2

Related Questions