Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring数据JPA中按类型查询_Java_Jpa_Spring Data_Spring Data Jpa - Fatal编程技术网

Java Spring数据JPA中按类型查询

Java Spring数据JPA中按类型查询,java,jpa,spring-data,spring-data-jpa,Java,Jpa,Spring Data,Spring Data Jpa,我有一个抽象类: @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.E

我有一个抽象类:

@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来只查询扩展了所需类型的对象?

您可以使用您定义的类型的鉴别器值的名称

@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);

为您的鉴别器添加只读属性,或者尝试从示例s中选择s,其中TYPEs=:type可能与我询问的第一个有关spring数据的内容重复,第二个我需要查询的不是type c,而是type c.objectA