小编meG*_*ind的帖子

Hibernate 返回 PersistentBag 而不是 List

我有以下关系 bw 下面给出的两个实体,当我从存储库中获取 OutletProductVariety 对象时,即使在使用 fetchtype Eager 之后,价格也会出现在 PersistentBag 中,而不是作为列表。

@Entity
public class OutletProductVariety  {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  Long id;

  @ManyToOne
  @JoinColumn(name = "varietyId")
  Variety variety;

  @OneToMany(mappedBy = "outletVariety", fetch = FetchType.EAGER)
  List<Price> price;
}
Run Code Online (Sandbox Code Playgroud)

@Entity
public class Price {

  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  Long Id;

  @ManyToOne
  @JoinColumn(name="outletVareityId")
  private OutletProductVariety outletVariety;

  private Double price;
}
Run Code Online (Sandbox Code Playgroud)

如何获得价格列表而不是 PersistentBag?

spring hibernate jpa spring-data-jpa spring-boot

5
推荐指数
1
解决办法
4786
查看次数

标签 统计

hibernate ×1

jpa ×1

spring ×1

spring-boot ×1

spring-data-jpa ×1