Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.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 冬眠可以';t读取多对多映射_Java_Hibernate_Many To Many - Fatal编程技术网

Java 冬眠可以';t读取多对多映射

Java 冬眠可以';t读取多对多映射,java,hibernate,many-to-many,Java,Hibernate,Many To Many,我有一个多对多映射:用户和房间,如下所示: User.java @Entity @Table(name="users", indexes = { @Index(unique=true, columnList="uid"), @Index(unique=true, columnList="backendAccessToken"), @Index(columnList="backendAccessToken", name="idx_backend")

我有一个多对多映射:用户和房间,如下所示:

User.java

@Entity
@Table(name="users", indexes = {
        @Index(unique=true, columnList="uid"),
        @Index(unique=true, columnList="backendAccessToken"),
        @Index(columnList="backendAccessToken", name="idx_backend")
})
public class User extends BasePersistable {
    private static final long serialVersionUID = 1492535311821424305L;

    @Column(nullable=false, unique=true)
    private String nickname;

    @Column(nullable=false)
    private Integer uid;

    @Column(nullable=false)
    private String backendAccessToken;

    @Column
    private String name;

    @Column
    @JsonIgnore
    private String email;

    @Column
    private String location;

    @Column
    private String company;

    @Column
    private String avatar;

    @Column
    @JsonIgnore
    private String accessToken;

    @CreationTimestamp
    private Date memberSince;

    @ManyToMany(targetEntity=Room.class, cascade={ CascadeType.PERSIST, CascadeType.MERGE })
    @JoinTable(name="room_users",
                joinColumns={ @JoinColumn(name="user_id") },
                inverseJoinColumns={ @JoinColumn(name="room_id") })
    private List<Room> rooms = new ArrayList<>();
@Entity
@Table(name="rooms", indexes = {
        @Index(unique=true, columnList="uid"),
        @Index(columnList="uid"),
        @Index(columnList="fullName")
})
public class Room extends BasePersistable {

    private static final long serialVersionUID = 1L;

    @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;

    @Column(nullable=false)
    private Integer uid;

    @Column(nullable=false)
    private String name;

    @Column(nullable=true)
    private String fullName;

    @Column(nullable=false)
    @Lob
    private String description;

    @Column(nullable=true)
    private String homepage;

    @Column(nullable=false)
    private String owner;

    @ManyToOne
    private Organization organization;

    @OneToMany(mappedBy="room")
    @JsonIgnore
    private List<Message> messages = new ArrayList<>();

    @ManyToMany(mappedBy="rooms", targetEntity=User.class)
    @JsonIgnore
    private List<User> users = new ArrayList<>();

    @Column(name="private")
    private Boolean _private = false;
@实体
@表(name=“users”,索引={
@索引(unique=true,columnList=“uid”),
@索引(unique=true,columnList=“backendAccessToken”),
@索引(columnList=“backendAccessToken”,name=“idx\u backend”)
})
公共类用户扩展BasePersistable{
私有静态最终长serialVersionUID=149253511821424305L;
@列(nullable=false,unique=true)
私有字符串昵称;
@列(nullable=false)
私有整数uid;
@列(nullable=false)
私有字符串backendAccessToken;
@纵队
私有字符串名称;
@纵队
@杰索尼奥雷
私人字符串电子邮件;
@纵队
私有字符串位置;
@纵队
私人弦公司;
@纵队
私有字符串化身;
@纵队
@杰索尼奥雷
私有字符串访问令牌;
@CreationTimestamp
自那时起的私人日期;
@ManyToMany(targetEntity=Room.class,cascade={CascadeType.PERSIST,CascadeType.MERGE})
@JoinTable(name=“房间用户”,
joinColumns={@JoinColumn(name=“user_id”)},
inverseJoinColumns={@JoinColumn(name=“room_id”)})
private List rooms=新建ArrayList();
Room.java

@Entity
@Table(name="users", indexes = {
        @Index(unique=true, columnList="uid"),
        @Index(unique=true, columnList="backendAccessToken"),
        @Index(columnList="backendAccessToken", name="idx_backend")
})
public class User extends BasePersistable {
    private static final long serialVersionUID = 1492535311821424305L;

    @Column(nullable=false, unique=true)
    private String nickname;

    @Column(nullable=false)
    private Integer uid;

    @Column(nullable=false)
    private String backendAccessToken;

    @Column
    private String name;

    @Column
    @JsonIgnore
    private String email;

    @Column
    private String location;

    @Column
    private String company;

    @Column
    private String avatar;

    @Column
    @JsonIgnore
    private String accessToken;

    @CreationTimestamp
    private Date memberSince;

    @ManyToMany(targetEntity=Room.class, cascade={ CascadeType.PERSIST, CascadeType.MERGE })
    @JoinTable(name="room_users",
                joinColumns={ @JoinColumn(name="user_id") },
                inverseJoinColumns={ @JoinColumn(name="room_id") })
    private List<Room> rooms = new ArrayList<>();
@Entity
@Table(name="rooms", indexes = {
        @Index(unique=true, columnList="uid"),
        @Index(columnList="uid"),
        @Index(columnList="fullName")
})
public class Room extends BasePersistable {

    private static final long serialVersionUID = 1L;

    @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;

    @Column(nullable=false)
    private Integer uid;

    @Column(nullable=false)
    private String name;

    @Column(nullable=true)
    private String fullName;

    @Column(nullable=false)
    @Lob
    private String description;

    @Column(nullable=true)
    private String homepage;

    @Column(nullable=false)
    private String owner;

    @ManyToOne
    private Organization organization;

    @OneToMany(mappedBy="room")
    @JsonIgnore
    private List<Message> messages = new ArrayList<>();

    @ManyToMany(mappedBy="rooms", targetEntity=User.class)
    @JsonIgnore
    private List<User> users = new ArrayList<>();

    @Column(name="private")
    private Boolean _private = false;
@实体
@表(name=“rooms”,索引={
@索引(unique=true,columnList=“uid”),
@索引(columnList=“uid”),
@索引(columnList=“fullName”)
})
公共教室可持久化{
私有静态最终长serialVersionUID=1L;
@Id@GeneratedValue(策略=GenerationType.IDENTITY)
私人长id;
@列(nullable=false)
私有整数uid;
@列(nullable=false)
私有字符串名称;
@列(nullable=true)
私有字符串全名;
@列(nullable=false)
@高球
私有字符串描述;
@列(nullable=true)
私人字符串主页;
@列(nullable=false)
私人字符串所有者;
@许多酮
私人组织;
@OneToMany(mappedBy=“房间”)
@杰索尼奥雷
私有列表消息=新的ArrayList();
@ManyToMany(mappedBy=“rooms”,targetEntity=User.class)
@杰索尼奥雷
private List users=new ArrayList();
@列(name=“private”)
私有布尔值_private=false;
当我尝试创建模式时,我看到了以下错误:
从com.models.User引用com.models.Room的外键的列数错误。应为2

我做了一些研究,尝试在
User
上使用
JoinColumns
注释,但没有成功

编辑
我发现了错误:类
BasePersistable
已经定义了
id
。所以我从
房间
中删除了
id
,并且成功了。感谢Mateusz Korwel和kakashihatake提供的提示,你能把
用户
房间
实体的完整代码放进去吗?你的加入colums的名字需要参考主键id对于类,因此您的room.class id列名称必须是“room\u id”,user.class必须是“user\u id”
room
实体包含由这两个字段组成的主键?@MateuszKorwel否,pkey是
id
您的user.class不包括ıd字段,如果BasePersistable,那么这次您的rom.class有两个id字段,所以id字段是错误的