CollectionOfElements上的java.util.ConcurrentModificationException

She*_*ari 8 java concurrency hibernate jpa

当我在Embedabble中有一个CollectionOfElements时,我似乎得到了一个ConcurrentModificationException.

如果想拥有它,那么如果我将Route从Embedabble更改为Entity,那么一切正常.我甚至尝试过添加@Version,但这似乎不起作用.

这是我的课程片段.Kart.java:

@Entity
public class Kart {

@Id @GeneratedValue
private Long id;

@Column(nullable=false,length=256)
@NotNull
@Length(max=256)
private String name;

@OneToOne(cascade=CascadeType.ALL)
private File file;

@Version
private int version;

@CollectionOfElements
private Set<Route> route;
Run Code Online (Sandbox Code Playgroud)

Route.java:

@Embeddable
public class Route {

@Parent
private Kart kart;

@NotNull
@Column(nullable = false, length = 256)
private String name;

@NotNull
@Column(nullable = false)
private Boolean visible = Boolean.valueOf(true);

@CollectionOfElements
private Set<Coordinates> coordinates;

@Version
private int version;
Run Code Online (Sandbox Code Playgroud)

Coordinates.java:

@Embeddable
public class Coordinates {

@NotNull
private int x;

@NotNull
private int y;

@Parent
private Route route;

@Version
private int version;
Run Code Online (Sandbox Code Playgroud)

我为Coordinates和Route生成了Hashcode/equals

jit*_*ter 9

检查此JIRA条目.

ConcurrentModificationException当embeddable的集合包含集合时

这是Annotation Binder中的已知错误.而问题在于Hibernate Core,它不支持嵌入式集合中的集合.

  • +1.在集合中嵌入不能拥有自己的任何集合,因为没有为要链接的那些(子)集合定义主键.你需要让Route成为一个实体,虽然你仍然可以让它的生命周期由Kart控制,因此在语义上它与DAO层之外的Embeddable没有区别. (2认同)