The column name id was not found in this ResultSet in java

Viewed 38

I want to enter data into a List according to the DB column options in the query, but I get an error when I do Doctor.class on createNativeQuery. how could this happen?

My code :

   StringBuilder stringBuilder = new StringBuilder();
   stringBuilder.append(" SELECT nama_lengkap,spesialis FROM dokter ");

   Query query = entityManager.createNativeQuery(stringBuilder.toString(), Dokter.class);

   List<Map<String,Object>> resultList = query.getResultList();

Error :

Caused by: org.postgresql.util.PSQLException: The column name id was not found in this ResultSet.
    at org.postgresql.jdbc.PgResultSet.findColumn(PgResultSet.java:2958)
    at org.postgresql.jdbc.PgResultSet.getLong(PgResultSet.java:2841)
    at io.agroal.pool.wrapper.ResultSetWrapper.getLong(ResultSetWrapper.java:320)
    at 
1 Answers

It's probably class Dokter has field @Id long id , you must include this table field into select statement, for example

select id, nama_lengkap, spesialis from dokter 
Related