gpt4 book ai didi

java - 找到同一集合异常的两种表示形式?

转载 作者:行者123 更新时间:2023-11-30 02:02:42 27 4
gpt4 key购买 nike

你好,我有以下代码:

@Entity
public class VirtualMeasure extends AbstractMeasure implements Record {

@OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.REMOVE}, mappedBy
= "virtualMeasureMyActionId.virtualMeasure")
@Access(AccessType.FIELD)
private Set<VirtualMeasureMyAction> vmMyAction;
}

@Entity
@AssociationOverrides({
@AssociationOverride(name = "virtualMeasureMyActionId.virtualMeasure",
joinColumns = @JoinColumn(name = "virtualMeasureId")),
@AssociationOverride(name = "virtualMeasureMyActionId.myAction",
joinColumns = @JoinColumn(name = "myActionId")) })
public class VirtualMeasureMyAction implements Record {

/**
* virtualMeasureViewId : VirtualMeasureViewId
*/
@EmbeddedId
private VirtualMeasureMyActionId virtualMeasureMyActionId;
}


@Embeddable
public class VirtualMeasureMyActionId implements Record {

@ManyToOne(fetch=FetchType.LAZY)
private VirtualMeasure virtualMeasure;


@ManyToOne(fetch=FetchType.LAZY)
private MyAction myAction;
}

在我运行的地方出现此错误[create]:javax.persistence.PersistenceException:org.hibernate.HibernateException:找到同一集合的两个表示:vmMyAction

最佳答案

问题是,当您坚持时, hibernate session 会检测到您在同一个 session 中两次拥有相同的集合。

注意不要在实体中重复 setter 和 getter,并使用 merge() 而不是 update()

关于java - 找到同一集合异常的两种表示形式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52312715/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com