Java 尝试使用多对多关系添加投票

Java 尝试使用多对多关系添加投票,java,annotations,many-to-many,playframework-2.1,Java,Annotations,Many To Many,Playframework 2.1,在我的play framework web应用程序中实现投票功能时遇到一些问题 目前,我已经在课堂上定义了这些变量,这些变量应该有一个投票的“分数” @ManyToMany(cascade=CascadeType.REMOVE) public List<User> upVotes = new ArrayList<User>(); @ManyToMany(cascade=CascadeType.REMOVE) public List<User> downVot

在我的play framework web应用程序中实现投票功能时遇到一些问题

目前,我已经在课堂上定义了这些变量,这些变量应该有一个投票的“分数”

@ManyToMany(cascade=CascadeType.REMOVE)
public List<User> upVotes = new ArrayList<User>();

@ManyToMany(cascade=CascadeType.REMOVE)
public List<User> downVotes = new ArrayList<User>();
似乎每当我将用户添加到向上投票列表时,它也会被添加到向下投票列表。投票功能似乎工作得很好,我还测试了模型,以确保所有工作正常。(测试工作正常,没有问题)我潜入创建表的sql文件,只能找到以下多个关系:

create table note_user (
  note_id                        bigint not null,
  user_id                        varchar(255) not null,
  constraint pk_note_user primary key (note_id, user_id))
;
为什么不创建两个表?我必须以某种方式命名多对多关系吗


我尝试了通过注释来命名表的方法,但没有找到任何解决方案。

我能够通过使用jointable注释来解决这个问题

@ManyToMany(cascade=CascadeType.REMOVE)
@JoinTable(name="up_votes")
public List<User> upVotes = new ArrayList<User>();

@ManyToMany(cascade=CascadeType.REMOVE)
@JoinTable(name="down_votes")
public List<User> downVotes = new ArrayList<User>();

我能够通过使用jointable注释解决这个问题

@ManyToMany(cascade=CascadeType.REMOVE)
@JoinTable(name="up_votes")
public List<User> upVotes = new ArrayList<User>();

@ManyToMany(cascade=CascadeType.REMOVE)
@JoinTable(name="down_votes")
public List<User> downVotes = new ArrayList<User>();

我认为您必须映射表。这会改变创建的表的数量吗?我认为您必须映射表。这会改变创建的表的数量吗?
create table up_votes (
  note_id                        bigint not null,
  user_id                        varchar(255) not null,
  constraint pk_up_votes primary key (note_id, user_id))
;

create table down_votes (
  note_id                        bigint not null,
  user_id                        varchar(255) not null,
  constraint pk_down_votes primary key (note_id, user_id))
;