找到两个表示相同集合例外的表示形式?

时间:2018-09-13 11:25:01

标签: java hibernate

您好,我有以下代码:

@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;
}

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

1 个答案:

答案 0 :(得分:0)

在vmMyAction中,您同时提供了@OneToMany(mappedBy)@Access。这是休眠状态在异常情况下告诉您的两种表示形式。 Hibernate一次也不支持。

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

由于自documentation起,@Access已被FIELD弃用,请尝试在没有@Access批注的情况下进行操作。