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

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b323df-2be10.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b323df-2be10.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?