码迷,mamicode.com
首页 > 系统相关 > 详细

Hibernate annotation多对多配置

时间:2014-07-08 18:26:30      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:hibernate

角色(用户组),用户多对多。

角色实体配置:

        private Set<TAuthUser> users;

	@ManyToMany
	@JoinTable(name="t_auth_user_role",joinColumns={@JoinColumn(name="role_id")},inverseJoinColumns={@JoinColumn(name="user_id")})//配置一方
	public Set<TAuthUser> getUsers() {
		return users;
	}


	public void setUsers(Set<TAuthUser> users) {
		this.users = users;
	}

用户实体配置:

        private Set<TAuthRole> roles;
	
	@ManyToMany(mappedBy="users")//"users"为在角色表中名称
	public Set<TAuthRole> getRoles() {
		return roles;
	}

	public void setRoles(Set<TAuthRole> roles) {
		this.roles = roles;
	}


测试生成角色表:

bubuko.com,布布扣


用户表:

bubuko.com,布布扣


角色用户关联表:

bubuko.com,布布扣

Hibernate annotation多对多配置,布布扣,bubuko.com

Hibernate annotation多对多配置

标签:hibernate

原文地址:http://blog.csdn.net/wintersweetsugar/article/details/37371697

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!