Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在hibernate注释中映射三个表_Java_Spring_Hibernate_Spring Mvc_Hibernate Annotations - Fatal编程技术网

Java 如何在hibernate注释中映射三个表

Java 如何在hibernate注释中映射三个表,java,spring,hibernate,spring-mvc,hibernate-annotations,Java,Spring,Hibernate,Spring Mvc,Hibernate Annotations,我的问题与下面的问题非常相似 因为我没有回答,所以我在这里再次提问。 我有用户、角色、应用程序表。如何在注释中对此进行映射。我试着像下面那样 @JoinTable(name = "role_application_user", joinColumns = @JoinColumn(name = "application_identifier"), inverseJoinColumns = @JoinColumn(name = "user_identif

我的问题与下面的问题非常相似

因为我没有回答,所以我在这里再次提问。 我有用户、角色、应用程序表。如何在注释中对此进行映射。我试着像下面那样

@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<>();
这是我的实体类

User.java

Class User{

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "CTC_AC_USER_INSTITUTION", joinColumns = {@JoinColumn(name = "userId")}, inverseJoinColumns = {@JoinColumn(name = "institutionId")})
private Set<Institution> institutions = new HashSet<Institution>();

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "CTC_AC_USER_USER_PROFILE", joinColumns = {@JoinColumn(name = "userId")}, inverseJoinColumns = {@JoinColumn(name = "userProfileId")})
private Set<UserProfile> userProfiles = new HashSet<UserProfile>();
Class UserProfile {
@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name = "type", length = 25, unique = true, nullable = false)
    @NotBlank
    private String type = UserProfileType.USER.getUserProfileType();
}
Class Institution{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Length(max = 500)
    @Column(name = "name", nullable = false)
    private String name;
}
Institution.java

Class User{

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "CTC_AC_USER_INSTITUTION", joinColumns = {@JoinColumn(name = "userId")}, inverseJoinColumns = {@JoinColumn(name = "institutionId")})
private Set<Institution> institutions = new HashSet<Institution>();

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "CTC_AC_USER_USER_PROFILE", joinColumns = {@JoinColumn(name = "userId")}, inverseJoinColumns = {@JoinColumn(name = "userProfileId")})
private Set<UserProfile> userProfiles = new HashSet<UserProfile>();
Class UserProfile {
@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name = "type", length = 25, unique = true, nullable = false)
    @NotBlank
    private String type = UserProfileType.USER.getUserProfileType();
}
Class Institution{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Length(max = 500)
    @Column(name = "name", nullable = false)
    private String name;
}

为什么你不能使用@Mohamed Nabli溶液?从上一个问题显示您的实体类。用POJOS更新了问题为什么不能使用@Mohamed Nabli solution?从上一个问题显示您的实体类。使用POJO更新了问题