gpt4 book ai didi

hibernate - org.hibernate.MappingException : Repeated column in mapping for collection using @JoinTable

转载 作者:行者123 更新时间:2023-12-02 23:04:06 25 4
gpt4 key购买 nike

我有以下(简化的)情况:

表 A 的字段:

  • 身份证
  • 通用

表 AB 的字段:

  • 援助
  • 出价通用

表 B 的字段:

  • 身份证
  • 通用

并且想要使用像这样的OneToMany将其与实体进行映射(在表A上映射的主类中):

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = false, fetch = FetchType.LAZY)
@JoinTable(name = "AB",
joinColumns= {
@JoinColumn(name = "AID", referencedColumnName="ID"),
@JoinColumn(name = "COMMONID", referencedColumnName="COMMONID")},
inverseJoinColumns = {
@JoinColumn(name = "BID", referencedColumnName="ID"),
@JoinColumn(name = "COMMONID", referencedColumnName="COMMONID")})
private Set<MyClassForB> list= new HashSet<MyClassForB>();

构建 session 时,出现以下错误:

org.hibernate.MappingException: Repeated column in mapping for collection using @JoinTable list column: COMMONID

我做错了什么?假设我是 Hibernate 新手。

最佳答案

尝试像这样添加可插入和可更新

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = false, fetch = FetchType.LAZY)
@JoinTable(name = "AB",
joinColumns= {
@JoinColumn(name = "AID", referencedColumnName="ID", insertable = false, updatable = false),
@JoinColumn(name = "COMMONID", referencedColumnName="COMMONID", insertable = false, updatable = false)},
inverseJoinColumns = {
@JoinColumn(name = "BID", referencedColumnName="ID", insertable = false, updatable = false),
@JoinColumn(name = "COMMONID", referencedColumnName="COMMONID", insertable = false, updatable = false)})
private Set<MyClassForB> list= new HashSet<MyClassForB>();

但我不确定您是否能够更新此集,我的用例是只读的。

关于hibernate - org.hibernate.MappingException : Repeated column in mapping for collection using @JoinTable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14734235/

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