ERROR: Column 'id' not found while using NativeQuery in Hibernate 5.4.14

127 Views Asked by At

I've following query :

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);

and there's filed id in entity and in a database too but getting

`Caused by: java.sql.SQLException: Column 'id' not found.`  

Here's entity class:

public class Client  implements java.io.Serializable {    

     private Integer id;
     private Product product;
     private String fullname;
     private String business;
     private String address;  

Here's 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>

enter image description here

I'm using MySQL 8.0.21 Hibernate 5.4.14 JDK 11.0.8+10
I don't want to use JPA Criteria query cuase I'm using NativeQuery to check performance.
So don't suggest JPA

0

There are 0 best solutions below