java - 错误:在 Hibernate 5.4.14 中使用 NativeQuery 时未找到列 'id'
问题描述
我有以下查询:
try (Session session = sessionFactory.openSession()) {
var clients = session.createNativeQuery("select c.fullname, c.city from client c where c.id=:id")
.addEntity("c", Client.class)
.setParameter("id", id);
并且在实体和数据库中也有归档的 id 但得到
`Caused by: java.sql.SQLException: Column 'id' not found.`
这是实体类:
public class Client implements java.io.Serializable {
private Integer id;
private Product product;
private String fullname;
private String business;
private String address;
这是 Client.hbm.xml :
<class name="javafxapplication.pojo.Client" table="client" catalog="clientie" optimistic-lock="version">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
我正在使用 MySQL 8.0.21 Hibernate 5.4.14 JDK 11.0.8+10
我不想使用 JPA Criteria 查询因为我正在使用 NativeQuery 来检查性能。
所以不建议使用JPA
解决方案
推荐阅读
- python - Tkinter:调用另一个 GUI 窗口但小部件没有响应
- python - 尝试读取 yaml 文件时出现错误“找到不可散列的密钥”
- javascript - 我正在尝试使用 JavaScript 生成随机颜色代码
- c++ - 如何在整个向量中查找某个字符的最后一次出现
然后将字符串拆分为三个单独的元素 - r - 使用 ReLU 的 R 神经网络进行负预测
- r - 如何使用 R 中 tfdatasets 的输入管道将包括图像在内的混合数据输入深度学习模型
- mysql - 如何使用 SUBSTR() 函数从字符串中删除两个不同字母的第 6 个字符
- css - 在 CSS 中我试图覆盖重要但失败了
- python - 使用 np.where 使用 Pandas 数据框中其他行的值
- r - 人为地将ggplot方块添加到标准图中