gpt4 book ai didi

java - 如何处理 hibernate 生成的唯一字段?

转载 作者:行者123 更新时间:2023-11-30 22:04:25 25 4
gpt4 key购买 nike

开门见山,我正在尝试构建以下逻辑来 hibernate 关系。

A Resource has many read groups.

A Resource has many write groups.

Both groups are Groups class.

到目前为止我做了什么:

ResourcePage.class

public class ResourcePage {
/*
useless code
*/
private Set read;
private Set write;
@OneToMany(cascade = CascadeType.ALL,
fetch = FetchType.EAGER,
targetEntity = Groups.class)
@JoinTable(name = "resourcepage_read_permissions")
public Set getRead() {
return read;
}

@OneToMany(cascade = CascadeType.ALL,
fetch = FetchType.EAGER,
targetEntity = Groups.class)
@JoinTable(name = "resourcepage_write_permissions")
public Set getWrite() {
return write;
}
/*
useless code
*/
}

表格按预期创建。

enter image description here

但是,hibernate 正在为 组的 id 生成一个唯一约束,这给我带来了一个大问题,因为有时两个不同的资源可能与读取组属于同一组。

enter image description here

你们是怎么处理的?我怎样才能让 hibernate 不生成这个唯一约束?

非常感谢。

最佳答案

您需要使用 @ManyToMany 而不是 @OneToMany

关于java - 如何处理 hibernate 生成的唯一字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42216098/

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