gpt4 book ai didi

java - EclipseLink 无法为 ManyToMany 创建完整的 JoinTable

转载 作者:太空宇宙 更新时间:2023-11-04 07:25:29 25 4
gpt4 key购买 nike

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

我有一个定义复合键(uuid、修订版)的映射父类(super class)Identifying。实体类 AppointmentContent 都是 Identifying 的子类。

现在我尝试定义从 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 注解,这对于具有复合键的目标实体是必需的。

我做错了什么吗?

您好,克雷特

最佳答案

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

您的 @JoinColumn 不得具有“updatable = false,insertable = false”,这没有任何意义,因为这样它将无法插入任何内容,这似乎就是正在发生的情况。

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

关于java - EclipseLink 无法为 ManyToMany 创建完整的 JoinTable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18610604/

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