我抽象课:
@Entity @Inheritance(strategy = InheritanceType.JOINED) public abstract class A { ... }
很少扩展类,如:
@Entity public class B extends A { ... }
我也有第三个实体:
@Entity public class C { @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER) private A objectA; ... }
问题是,我如何在C实体存储库中构造Spring Data JPA finder,以仅查询扩展A所需类型的对象?
您可以使用已定义"类型"的鉴别器值的名称
@Entity @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING) @Table(name = "abc") public abstract class Abc { .... ------------------------------------------- @Query("select a from Abc a where type = ?1") List<Abc> findByType(String typeValue);