我有一些角色,用户和应用程序 我想创建该表的映射休眠:Hibernate:如何通过Annotation在一个连接表中连接3个表?
CREATE TABLE role_application_user (
role_identifier INTEGER not null,
application_identifier INTEGER not null,
user_identifier INTEGER not null,
KEY FK_role_identifier (role_identifier),
KEY FK_application_identifier(application_identifier),
KEY FK_user_identifier (user_identifier),
CONSTRAINT FK_role_identifier FOREIGN KEY (role_identifier) REFERENCES role (identifier),
CONSTRAINT FK_application_identifier FOREIGN KEY (application_identifier) REFERENCES application (identifier),
CONSTRAINT FK_user_identifier FOREIGN KEY (user_identifier) REFERENCES users (login)
);
一个应用程序,一个角色可以有很多的用户,并且用户可以在多个角色。
我试试这个映射:
Application.java
@JoinTable(name = "role_application_user",
joinColumns = @JoinColumn(name = "application_identifier"),
inverseJoinColumns = @JoinColumn(name = "user_identifier"))
@MapKeyJoinColumn(name = "role_identifier")
@ElementCollection
private Map<Role, User> userByRole = new HashMap<>();
不幸的是,这不是我的情况,因为在Java中工作,一个地图的关键必须是唯一的。
通过此映射,我们只能为角色和应用程序提供一个用户。
这里是你的答案https://developer.jboss.org/thread/168634?tstart=0 – Sitansu
你得到了解决? – Rajesh