JPA多对多问题,跪求释疑
有3个表
/**
* 角色基本信息
*
*/
@SuppressWarnings("serial")
@Entity
@Table(name="Role", catalog="hiic",schema="dbo")
public class Role implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
//编号,名称
@Id
private String id;
private String name;
private String description;
//用户列表 List<User>
@ManyToMany(cascade = CascadeType.REFRESH,mappedBy = "roleSet", fetch = FetchType.LAZY)
private Set<User> userSet =new HashSet<User>();
//操作权限列表 List<Operation>
@ManyToMany(cascade = CascadeType.REFRESH)
@JoinTable( catalog="ManyToMany", name="RoleOperation",joinColumns={@JoinColumn(name="id")},inverseJoinColumns={@JoinColumn(name="RoleOperationPK.operation")} )
private Set<Operation> operationSet =new HashSet<Operation>();
public Set<Operation> getOperationSet() {
return operationSet;
}
public void setOperationSet(Set<Operation> operationSet) {
this.operationSet = operationSet;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Set<User> getUserSet() {
return userSet;
}
public void setUserSet(Set<User> userSet) {
this.userSet = userSet;
}
操作权限
@SuppressWarnings("serial")
@Entity
//@Table(name="Operation", catalog="hiic",schema="dbo")
public class Operation implements java.io.Serializable {
//编号
@Id
@GeneratedValue
private String id;
//名称
private String name;
//描述
private String description;
//顺序
@Enumerated(EnumType.ORDINAL)
private Integer sequenceq;
//功能模块
private String module;
//角色列表
@ManyToMany(cascade = CascadeType.REFRESH, mappedBy = "operationSet", fetch = FetchType.LAZY)
// @ManyToMany(mappedBy = "operationSet")
private Set<Role> roleSet= new HashSet<Role>();
public Set<Role> getRoleSet() {
return roleSet;
}
public void setRoleSet(Set<Role> roleSet) {
this.roleSet = roleSet;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getSequenceq() {
return sequenceq;
}
public void setSequenceq(Integer sequenceq) {
this.sequenceq = sequenceq;
}
public String getModule() {
return module;
}
public void setModule(String module) {
this.module = module;
}
}
这两个表是多对多的,下面是中间表
//角色操作
@SuppressWarnings("serial")
@Entity
//@Table(name="RoleOperation", catalog="hiic",schema="dbo")
public class RoleOperation implements Serializable{
/**
*
*/
private RoleOperationPK id;
public RoleOperation(){
}
public RoleOperation(RoleOperationPK