@MappedSuperClass 上的 JPA 查询。获取所有 child class 的详细信息?
JPA query on @MappedSuperClass. Fetch details of all the child class?
我有 3 个单选按钮 1.Car, 2.Bike, 3.Both。所以如果我 select
car 它将获取所有汽车详细信息,如果我 select 2 它只会
获取汽车详细信息,直到我能够实现,但如何实现
如果我 select 第三个单选按钮,则获取汽车和自行车的详细信息
"both"。在下面的示例中,我想在 selecting "both" 上做同样的事情
它将获取所有文件。最好的解决方案是什么?
Parent class:
@MappedSuperclass
public abstract class BaseProsecutionDocument {
private long dmsDocumentId;
private long documentVersion;
private String fileName;
…
}
Pros class:
@Entity
@Table(schema = “reference”, name = “prosecution_documents”)
public class ProsDocument extends BaseProsecutionDocument {
private Long id;
private Long prosId;
private Long ocportalSubmissionId;
…
}
Sumisiion class:
@Entity
@Immutable
@Table(schema = “reference”, name = “submission_docs”)
public class submissionDocument extends BaseProsecutionDocument {
private Long id;
private Long inventionId;
…
}
I want to know how to write the query for that..like
i have written for those 2 radio buttons:
public interface ProsecutionDocumentRepository extends JpaRepository {
@Query(value = “SELECT ppd FROM ProsDocument ppd ” +
“WHERE ppd.submissionId IN (SELECT p.id FROM submission p WHERE
UPPER(p.doc) = UPPER(:doc)) ” +
“AND ppd.documentType.documentType in (‘OFFICE’)”)
Page findSubmissionOfficeDocumentsByDoc(@Param(“doc”) String docket,
Pageable pageable);
}
Or do I need to change the @MappedSuperClass to @Entity and use
@Inheritance(strategy = InheritanceType.JOINED)
首先用基本字段
创建一个基础Class
@MappedSuperclass
public class FooBase {
@Id
private Long id;
private String name;
}
将此 class 映射到空 class
上的 table
@Entity
@Table(name = "foo")
public class Foo extends FooBase{
}
将嵌套对象、集合、子资源映射到另一个 class 但相同 table "foo"
@Entity
@Table(name = "foo")
public class FooNested extends FooBase {
@Fetch(FetchMode.SUBSELECT)
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "foo_id", insertable = false, updatable = false)
@ApiModelProperty(hidden = true)
private List<Bar> barList;
}
为每个实体创建一个 Reporitory
使用一个或其他存储库来 FETCh 或不是真实的 tables/entities
我有 3 个单选按钮 1.Car, 2.Bike, 3.Both。所以如果我 select car 它将获取所有汽车详细信息,如果我 select 2 它只会 获取汽车详细信息,直到我能够实现,但如何实现 如果我 select 第三个单选按钮,则获取汽车和自行车的详细信息 "both"。在下面的示例中,我想在 selecting "both" 上做同样的事情 它将获取所有文件。最好的解决方案是什么?
Parent class:
@MappedSuperclass
public abstract class BaseProsecutionDocument {
private long dmsDocumentId;
private long documentVersion;
private String fileName;
…
}
Pros class:
@Entity
@Table(schema = “reference”, name = “prosecution_documents”)
public class ProsDocument extends BaseProsecutionDocument {
private Long id;
private Long prosId;
private Long ocportalSubmissionId;
…
}
Sumisiion class:
@Entity
@Immutable
@Table(schema = “reference”, name = “submission_docs”)
public class submissionDocument extends BaseProsecutionDocument {
private Long id;
private Long inventionId;
…
}
I want to know how to write the query for that..like
i have written for those 2 radio buttons:
public interface ProsecutionDocumentRepository extends JpaRepository {
@Query(value = “SELECT ppd FROM ProsDocument ppd ” +
“WHERE ppd.submissionId IN (SELECT p.id FROM submission p WHERE
UPPER(p.doc) = UPPER(:doc)) ” +
“AND ppd.documentType.documentType in (‘OFFICE’)”)
Page findSubmissionOfficeDocumentsByDoc(@Param(“doc”) String docket,
Pageable pageable);
}
Or do I need to change the @MappedSuperClass to @Entity and use @Inheritance(strategy = InheritanceType.JOINED)
首先用基本字段
创建一个基础Class@MappedSuperclass public class FooBase { @Id private Long id; private String name; }
将此 class 映射到空 class
上的 table@Entity @Table(name = "foo") public class Foo extends FooBase{ }
将嵌套对象、集合、子资源映射到另一个 class 但相同 table "foo"
@Entity @Table(name = "foo") public class FooNested extends FooBase { @Fetch(FetchMode.SUBSELECT) @OneToMany(fetch = FetchType.EAGER) @JoinColumn(name = "foo_id", insertable = false, updatable = false) @ApiModelProperty(hidden = true) private List<Bar> barList; }
为每个实体创建一个 Reporitory
使用一个或其他存储库来 FETCh 或不是真实的 tables/entities