我有一个双向地图映射。读取有效,但 Hibernate 不存储映射键列。当我签入调试器时,一切都设置好了。
INSERT 查询是:
insert into rel_custField (field_id, release_id, value, id) values (22, 1, 'fwefwe', 3)
它还应该包含设置name
列。我应该如何做到这一点?
也许问题是地图项实体没有name
属性?但我从未在 docs/spec 中看到它应该这样做。
如果我选择该解决方案,我将不得不手动设置 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;
....
}