日期:2014-05-17  浏览次数:20770 次

关于表关联的一个问题
public class Role implements Serializable{
private Integer id; //主键
private String name; //角色名称
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}


public class User {
private Integer id; //主键
private String username; //登录用户
private String password; //登录密码
private Role role; //角色ID

@Id
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "role_id")
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
} public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}这样关联了以后
表user有id,username,password,role_id,4个属性
我在存role_id 的时候怎么存啊



------解决方案--------------------
role_id 你在写bean时都写错了。this.role_id=setRole_Id(this.getId);