User 表:
@ManyToMany(cascade =
{ CascadeType.MERGE })
@JsonIgnore
@JoinTable(name =
"UserRole", joinColumns = { @JoinColumn(name =
"user_id", referencedColumnName =
"id") }, inverseJoinColumns =
{
@JoinColumn(name =
"role_id", referencedColumnName =
"id") })
private Collection<Role> roles;
Role表:
@ManyToMany(mappedBy =
"roles")
@Basic(fetch =
FetchType.EAGER)
private Collection<User> users;
转载于:https://www.cnblogs.com/lambertwe/p/10936993.html
相关资源:Eclipse下如何配置JPA生成数据库表对应的已注解实体类(图文详解)