I am trying to write a query to look for an attribute of a subclass that is not in its superclass and return all objects of the superclass. I am currently getting a NullPointerException when I try to make person.get ("specialAttribute").
@Inheritance(strategy = InheritanceType.JOINED)
@Entity
public abstract class Person {
public String searchableAttribute;
}
@Entity
@Table( name = "normal_person" )
public class NormalPerson extends Person {
}
@Entity
@Table( name = "special_person" )
public class SpecialPerson extends Person {
@Column(nullable = false, unique = true)
public String specialAttribute;
}
Root<Person> person = query.from(Person.class);
query.where(
builder.or(
builder.like(person.<String>get("specialAttribute"), "foo"),
builder.like(person.<String>get("searchableAttribute"), "foo")
)
);
source
share