1
我有Order's
其中包含一堆Product's
和數量。多列多列僅返回一行
我Order
實體:
@Entity(name = "orders") // Select * from order order by... NO!
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@OneToMany(mappedBy = "product", cascade = ALL, orphanRemoval = true, fetch = EAGER)
private List<OrderEntity> orderEntities = new ArrayList<>();
...
orders
和products
之間的關係如下:
@Entity
public class OrderEntity implements Serializable {
@Id
@ManyToOne
@JsonIgnore
private Order order;
@Id
@ManyToOne(fetch = EAGER)
private Product product;
private int quantity;
...
我product
如下:
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String name;
@OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true)
private List<OrderEntity> orderEntity;
...
的問題是,當我選擇了order
由它的id
我只收到一個OrderEntity
回來,即使我可以通過查看數據庫表來看到有幾個與order
關聯。任何人都知道我做錯了什麼?