【发布时间】:2019-01-15 09:08:49
【问题描述】:
我有两张表 Product 和 Price。产品可以有多个价格,具体取决于时间段。
产品实体:
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
String name;
@OneToMany(mappedBy = "product", fetch = FetchType.EAGER)
List<Price> price;
}
价格实体:
@Entity
public class Price {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
LocalDate timePeroid;
Double price;
@ManyToOne()
Product product;
}
我想要 3 个动态日期中的时间段的产品实体。但如果时间段不存在,那么我也应该有产品实体,但标价应该包含三个空值。我如何在 JPA 中编写查询。?
【问题讨论】:
标签: spring spring-boot jpa spring-data-jpa spring-data