hibernate多对多中间表的保存问题
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();}这样才能正常保存