gpt4 book ai didi

java - JPA/Hibernate 不存储@MapKeyColumn 的值

转载 作者:行者123 更新时间:2023-11-29 09:06:47 26 4
gpt4 key购买 nike

我有一个双向 map 映射。阅读有效,但 Hibernate 不存储映射键列。当我 checkin 调试器时,一切都已按预期设置。

INSERT 查询是:

insert into rel_custField (field_id, release_id, value, id) values (22, 1, 'fwefwe', 3)

它还应该包含设置 name 列。 我应该如何实现?

也许问题是 map 项实体没有 name 属性?但我从未在文档/规范中看到它应该如此。
如果我选择该解决方案,我将不得不手动设置 name 属性,这似乎不切实际且多余。

@SuppressWarnings("serial")
@Entity @Table(name="`release`")
public class Release implements Serializable, IHasTraits {

@MapKeyColumn(name = "name")
@OneToMany(mappedBy = "release", cascade = CascadeType.ALL )
//@JoinColumn(referencedColumnName = "release_id") // Only at one side.
private Map<String, ReleaseCustomField> customFields = new HashMap();

...
}

@Entity
@Table(name = "rel_custField", uniqueConstraints = {
@UniqueConstraint(name = "rel_prodcf", columnNames = {"release_id", "field_id"})
})
public class ReleaseCustomField implements Serializable {

@Id @GeneratedValue( strategy = GenerationType.AUTO )
private Long id;

// Make uni-dir?
@ManyToOne(optional = false)
@JoinColumn(name = "release_id", nullable = false, updatable = false)
private Release release;

....
}

最佳答案

根据我在这里找到的描述:http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Map_Key_Columns_.28JPA_2.0.29

它不应该是目标实体的属性,而是列名。例如:

@MapKeyColumn(name = "id")
@OneToMany(mappedBy = "release", cascade = CascadeType.ALL )
private Map<String, ReleaseCustomField> customFields = new HashMap();

关于java - JPA/Hibernate 不存储@MapKeyColumn 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14587148/

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