【问题标题】:EclipseLink fails to create complete JoinTable for ManyToManyEclipseLink 无法为 ManyToMany 创建完整的 JoinTable
【发布时间】:2013-09-07 18:28:08
【问题描述】:

我目前正在为一个项目使用 EclipseLink 2.5,但遇到了一个多对多关系的小问题:

我有一个映射超类Identifiable,它定义了一个复合键(uuid,修订版)。实体类AppointmentContent 都是Identifiable 的子类。

现在我尝试定义从AppointmentContent 的单向ManyToMany 关系,但EclipseLink 似乎没有创建JoinTable 权限。其中只有两列(uuid,修订版),但应该有四列(关系的每一侧都有一个 uuid 和修订版)。

欲望但并非最不重要的,代码:

@MappedSuperclass
@IdClass(IdentifiablePK.class)
public abstract class Identifiable implements Serializable {

    @Id
    @UuidGenerator(name = "uuid")
    @GeneratedValue(generator = "uuid")
    protected String uuid;

    @Id
    protected Integer revision;

    /* ... */
}
public class Appointment extends Identifiable {

    @JoinColumns({
        @JoinColumn(columnDefinition = "trainingcontent_uuid", referencedColumnName = "uuid", nullable = false, updatable = false, insertable = false),
        @JoinColumn(columnDefinition = "trainingcontent_revision", referencedColumnName = "revision", nullable = false, updatable = false, insertable = false)
    })
    @ManyToMany(fetch = FetchType.LAZY)
    protected List<TrainingContent> trainingContents;

    /* ... */
}
public class TrainingContent extends Identifiable {
    /* ... */
}

我也尝试使用@JoinTable 代替@JoinColumns,但随后EclipseLink 抱怨缺少相应不完整的@JoinColumns 注释,这对于具有复合键的目标实体是必需的。

我是不是做错了什么?

您好, chret

【问题讨论】:

    标签: java jpa many-to-many eclipselink


    【解决方案1】:

    对于ManyToMany,您必须使用@JoinTable 到@JoinColumns,源和目标连接列在@JoinTable 中指定。

    你的@JoinColumn 不能有,“updatable = false, insertable = false”,这是没有意义的,因为那样它就不能插入任何东西,这似乎是正在发生的事情。

    看, https://en.wikibooks.org/wiki/Java_Persistence/ManyToMany

    【讨论】:

    • 如上所述,我已经尝试使用@JoinTable (joinColumns + inverseJoinColumns) 而不是@JoinColumns,但随后EclipseLink 抱怨缺少@JoinColumns 注释。删除可更新的、可插入的也不起作用!顺便说一句:我还尝试用多对一替换多对多关系,这也不起作用......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-23
    • 1970-01-01
    • 1970-01-01
    • 2011-04-30
    • 2021-01-30
    • 2012-06-03
    • 1970-01-01
    相关资源
    最近更新 更多