相关疑难解决方法(0)

Hibernate无法同时获取多个行李

Hibernate在SessionFactory创建期间抛出此异常:

org.hibernate.loader.MultipleBagFetchException:无法同时获取多个行李

这是我的测试用例:

Parent.java

@Entity
public Parent {

 @Id
 @GeneratedValue(strategy=GenerationType.IDENTITY)
 private Long id;

 @OneToMany(mappedBy="parent", fetch=FetchType.EAGER)
 // @IndexColumn(name="INDEX_COL") if I had this the problem solve but I retrieve more children than I have, one child is null.
 private List<Child> children;

}
Run Code Online (Sandbox Code Playgroud)

Child.java

@Entity
public Child {

 @Id
 @GeneratedValue(strategy=GenerationType.IDENTITY)
 private Long id;

 @ManyToOne
 private Parent parent;

}
Run Code Online (Sandbox Code Playgroud)

这个问题怎么样?我能做什么?


编辑

好吧,我遇到的问题是另一个"父"实体在我父母的内部,我的真实行为是这样的:

Parent.java

@Entity
public Parent {

 @Id
 @GeneratedValue(strategy=GenerationType.IDENTITY)
 private Long id;

 @ManyToOne
 private AntoherParent anotherParent;

 @OneToMany(mappedBy="parent", fetch=FetchType.EAGER)
 private List<Child> children;

}
Run Code Online (Sandbox Code Playgroud)

AnotherParent.java

@Entity …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa

428
推荐指数
8
解决办法
29万
查看次数

标签 统计

hibernate ×1

java ×1

jpa ×1