5
슈퍼 클래스에없는 서브 클래스 속성을 검색하고 슈퍼 클래스의 모든 객체를 반환하는 쿼리를 작성하려고합니다. 현재 person.get ("specialAttribute")을 시도 할 때 NullPointerException이 발생합니다.JPA CriteriaQuery로 하위 클래스 속성을 검색하는 방법은 무엇입니까?
@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;
}
// Controller method
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")
)
);