Skip to content
Advertisement

NamedQuery returning entities with null fields

defined entity with namedquery as SELECT mdl FROM tbl_slots mdl where mdl.test_date between :dt and :dt order by mdl.test_time asc

if used * instead of mdl in query, JPA gives error unexpected token: *

if mentioned the column names in select statement it returns entities with respective fields populated with expected values

[{ “srNo”: 1, “testDate”: “2021-Dec-30”, “testTime”: “09:00-10:00”, },{ “srNo”: 2, “testDate”: “2021-Dec-30”, “testTime”: “11:00-12:00”, }]

how to get same result without mentioning column names in select statement as if used *?

what’s valid JPQL or HQL for select * from table query?

Entity class

JavaScript

Advertisement

Answer

JPQL understand java entities and not columns.

how to get same result without mentioning column names in select statement as if used *?

what’s valid JPQL or HQL for select * from table query?

So a valid JQPL SELECT query can even not have the SELECT clause.

The following would be a valid JPQL query to return the complete entities from that table

JavaScript

So your annotation could be written as

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement