hibernate中@ManyToMany中的疑问

yang_7115 2014-03-26 09:47:46
roleGroup表

@Table(name="news_roleGroup")
public class RoleGroup {
private int id; //角色组ID(主键)
private String roleGroupName; //角色组名字(唯一)
private Set<Permission> permissiones=new HashSet<Permission>(); //角色组所包含的权限
@Column(name="roleGroup_id")
@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid",strategy="uuid")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name="roleGrope_name",length=15,nullable=false,unique=true)
public String getRoleGroupName() {
return roleGroupName;
}
public void setRoleGroupName(String roleGroupName) {
this.roleGroupName = roleGroupName;
}
@ManyToMany(
targetEntity=com.webnews.entity.Permission.class,
mappedBy="roleGroups", 不知道这个mappedBy能不能写
cascade=CascadeType.ALL,
fetch=FetchType.LAZY)
public Set<Permission> getPermissiones() {
return permissiones;
}
public void setPermissiones(Set<Permission> permissiones) {
permission表
[code=java]
@Entity
@Table(name="news_permission")
public class Permission {
private int id; //权限ID(主键)
private String permissionName; //权限名字(唯一)
private Set<RoleGroup> roleGroups=new HashSet<RoleGroup>(); //权限所属角色组
@Column(name="permission_id")
@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid",strategy="uuid")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name="permission_name",length=15,nullable=false,unique=true)
public String getPermissionName() {
return permissionName;
}
public void setPermissionName(String permissionName) {
this.permissionName = permissionName;
}
@ManyToMany(
targetEntity=com.webnews.entity.RoleGroup.class,
cascade=CascadeType.ALL,
fetch=FetchType.LAZY)
@JoinTable(
name="permission_roleGroup",
joinColumns={@JoinColumn(name="permission_id")},
inverseJoinColumns={@JoinColumn(name="roleGroup_id")}
)
public Set<RoleGroup> getRoleGroup() {
return roleGroups;
}
public void setRoleGroup(Set<RoleGroup> roleGroups) {
this.roleGroups = roleGroups;
}


出现以下错误,求大大们看看

...全文
182 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yang_7115 2014-03-27
  • 打赏
  • 举报
回复
哪位大大 帮忙解答一下吧!!自己顶一个!!!
yang_7115 2014-03-26
  • 打赏
  • 举报
回复
单向的 就没错 双向的就报错了 求大大们解答一下 小弟感激不敬啊!!!
yang_7115 2014-03-26
  • 打赏
  • 举报
回复
恩 !但为啥就报错呢?不明白啊!
ay转身遇 2014-03-26
  • 打赏
  • 举报
回复
去掉之后就是单向了。。
yang_7115 2014-03-26
  • 打赏
  • 举报
回复
还有就是 我把mappedBy去掉之后就是对的,但是去掉之后还是不是双向关联的啊?
yang_7115 2014-03-26
  • 打赏
  • 举报
回复
哦,哪个实际上不属于代码,发帖时不小心贴上去了
ay转身遇 2014-03-26
  • 打赏
  • 举报
回复
<span>......没见过这样写法,.把它去掉呢?
yang_7115 2014-03-26
  • 打赏
  • 举报
回复
出现的是这个错 mappedBy reference an unknown target entity property: com.webnews.entity.Permission.roleGroups in com.webnews.entity.RoleGroup.permissiones

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧