假如是用户表与权限表的多对多,其中用户表中的注解配置:
// 权限
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "user_permission", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "permission_id"))
public List<Permission> permissionList;
权限表中的注解配置:
//用户
@ManyToMany(cascade = CascadeType.ALL, mappedBy = "permissionList", fetch = FetchType.LAZY)
public List<User> ownerList;
在进行保存时:通过保存User表来查询Permission权限表。