如何根据用户 id 从两个表中获取数据? * ** * ** * ** * ** * ** * *角色类* ** * ** * ** * ** * ** * ** * ** * *
@Entity
@Table(name = "IUC_CON_USER_ROLE_MAP")
public class Role {
@Id
@Column(name="F_ROLE_MAP_ID")
int rolemap;
@Column(name="F_ROLE_ID")
int roleid;
@OneToMany(mappedBy="role",fetch=FetchType.EAGER)
Set<User> F_USER_ID;
** * ** * ** * ** * ** * ** * ** *用户类* ** * ** * ** * ** * ** * ** *
@Entity
@Table(name = "IUC_CON_USER")
public class User implements Serializable {
@Id
@Column(name = "F_USER_ID")
private int id;
@Column(name = "F_USER_NAME")
private String name;
@Column(name = "F_USER_PWD")
private String pwd;
@ManyToOne
@JoinColumn(name="F_USER_ID",insertable=false,updatable=false)
private Role role;
----------setter and getter for properties
}
外部编辑:标准创建代码:
DetachedCriteria uCrit = DetachedCriteria.forClass(User.class, "user");
uCrit.add(Restrictions.eq("user.id", 5));
uCrit.setProjection(Projections.property("user.id"));
DetachedCriteria criteria = DetachedCriteria.forClass(Role.class, "role");
criteria.add(Property.forName("role.F_USER_ID").in(uCrit));
List lt1 = criteria.getExecutableCriteria(getSession()).list();