我有这样的关系:一个房间有很多用户,一个用户属于很多房间。我真的不需要用户之间的连接 - >房间,所以我删除并休眠创建了一个名为room_users
的关系表,这很好
而且,创建了这两个索引:
您可以想象,uk_rdxxx
索引是错误的,并且不允许我为每个房间保存多个用户。而且我不知道它来自哪里。这是我的班级:
@Entity
@Table(name = "rooms", indexes = {
@Index(columnList = "uid", unique = true),
@Index(columnList = "fullName", name = "full_name_idx")
})
@JsonInclude(content = Include.NON_NULL)
@Data
@EqualsAndHashCode(callSuper = true, of = {"uid"})
@ToString(of = {"name", "uid", "fullName"})
@NamedEntityGraphs(
@NamedEntityGraph(name = "with-messages",
attributeNodes = {@NamedAttributeNode("messages")}))
public class Room extends AbstractAggregateRoot implements Serializable {
@OneToMany(targetEntity = User.class, cascade = {})
@JsonIgnore
private Set<User> users = new HashSet<>();