ITeye博客

hibernate多对多中间表的保存问题

DLFSEEIT · 2013-03-23 14:22 · hibernate · 企业架构 · Hibernate · 保存 · 多对多 · 中间表 · Markdown

  1. 表的设计 a. 角色表 b. 权限表 c. 角色_权限表

2.代码


  RoleAuthority roleAuthority = new RoleAuthority();
					
  roleAuthority.getAuthority().setAuthorityId(authorityId);
  roleAuthority.getRole().setRoleId(roleId);
  this.saveOrUpdateEntity(roleAuthority);
 

以直报空指针错,发现roleAuthority.getAuthority()为空 然后想新new的对象的子对象怎么样才能不为空,只有在初始化的时候


	/** default constructor */
	public YbRoleAuthority() {
		this.ybRole = new YbRole();
		this.ybAuthority = new YbAuthority();
	}

这样才能正常保存

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。