我想在hibernate中查询两个表.用户实体中的featch 3表(用户 - 角色 - 配置文件).用hql查询:
query= "select ue, ue.roleEntity.roleId from UserEntity ue ,RoleEntity re fetch all properties where ue.roleEntity.roleId=re.roleId and ue.username ='reza' and ue.password='123456'";
Run Code Online (Sandbox Code Playgroud)
并运行查询:
try {
sessionFactory = HibernateUtil.getSessionFactory();
session = sessionFactory.getCurrentSession();
transaction = session.beginTransaction();
userEntityList = (List<UserEntity>) session.createQuery(query).list();
transaction.commit();
} catch (HibernateException e) {
try {
throw new DaoException("Fetal exception in", e);
} catch (DaoException e1) {
e1.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
userentity class:这个类是geteer和seter:
public class UserEntity {
private int userId;
private long personalCode;
private String username;
private String …Run Code Online (Sandbox Code Playgroud)