小编rez*_*ami的帖子

java.lang.ClassCastException:[Ljava.lang.Object; 无法强制转换为entity.UserEntity

我想在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)

java orm hibernate hql java-ee

8
推荐指数
1
解决办法
3万
查看次数

标签 统计

hibernate ×1

hql ×1

java ×1

java-ee ×1

orm ×1