问题描述
因此,如果某些表缺少主键,则innodb的行为可能会导致问题.
So, there is that behavior with innodb that can cause problem if some tables lack of primary key.
因此,对于Hibernate,我正在寻找一个键来指定@ElementCollection表上的主键,并使用Set作为基础数据结构.
So with Hibernate, I am looking for a key to specifies a primary key on a @ElementCollection table with a Set as the underling data structure.
我找到了一种在地图上拥有主键的方法,但这有点奇怪,因为我不需要地图.
I found a way to have a primary key with a map, but it is kind of weird because I do not need a map.
我也找到了与@Embeddable相关的答案,但是我不需要那种复杂性.我在实体中使用Set或Set作为数据结构.
I also found an answer related to @Embeddable, but I do not need that kind of complexities. I am using a Set or Set as the data structure in my entities.
有什么想法要实现吗?
推荐答案
如果使用Set并将元素Column设置为非null,则hibernate将使用join列和element列作为主键.
If you use a Set and make the element Column be not null, then hibernate will make a primary key with the join column and element column.
示例:
@Column(name = "STRINGS", nullable = false)
@ElementCollection
private Set<String> strings;
这篇关于如何在@ElementCollection上指定主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!