java - 表和实体映射的休眠查询异常
问题描述
我收到如下错误:
org.hibernate.hql.internal.ast.QuerySyntaxException: Employee is not mapped [from Employee]; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Employee is not mapped [from Employee]",
"trace": "org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.internal.ast.QuerySyntaxException: Employee is not mapped [from Employee];
我创建了如下所示的模态
@Entity
@Table(name="employee_list")
public class Employee {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column
private Integer id;
@Column
private String name;
@Column
private String gender;
@Column
private String department;
@Column
private Date dob;
// getters/setters
}
我的道实现:
@Repository
public class EmployeeDAOImpl implements EmployeeDAO {
@Autowired
private EntityManager entityManager;
@Override
public List<Employee> get() {
Session currentSession = entityManager.unwrap(Session.class);
Query<Employee> query = currentSession.createQuery("from Employee", Employee.class);
List<Employee> list = query.getResultList();
return list;
}
}
我错过了一些东西。
我无法确定到底是什么。
解决方案
HQL应该如下所示:
currentSession.createQuery("select e from Employee e", Employee.class);
此外,您可以使用Criteria API:
currentSession.createCriteria(Employee.class).list();
有用的参考资料:
推荐阅读
- javascript - 没有“未捕获的引用错误:未定义道具”的解构
- c# - Asp.NET:如何发送位于共享中的文件
- cython - cython中dealloc中的Python对象
- python - Numpy 将所有值跳过一个并从中创建一个数组
- azure - 对复杂对象上的 ScoringProfile 字段应用权重
- html - 如何使下拉菜单出现在每个悬停按钮上?
- angular - 如何在一行中验证所有输入的属性?
- javascript - 有没有办法可以将 $set 与条件一起使用?
- reactjs - 在物理设备上运行本机 ios 应用程序时出现签名问题
- cesium - Cesium 没有很好地定位 GLTF 文件