Does the field queried by JPA have to correspond to the entity?

User entity has id,name,age

I use @ Query (nativeQuery = true, value = "select id,name from user")
to find only 2 fields

tells me that age is missing and that I have to find out all the fields in the entity. If I have 100 fields, I need 100. isn"t that a lot of performance? What if I only find out some of the fields and I can bind them with entities?

I don"t want to return List < Object [] >. It"s not intuitive. How do I want to save it with an entity?

May.08,2022

then don't use @ Query annotations
you can do this

User findByUserId (Long userId)


use tdo interface to save data

Menu