Doubt regarding JPA namedquery

假装没事ソ 提交于 2019-11-29 18:44:39

Below is the sample query which fetches only the required fields, but have to make such constructor for it.

Query : SELECT NEW package_name.Employee(e.username,e.email,e.image,e.firstname,e.lastname) FROM Employee e where e.empid=?1;

It will return Employee entity with selected fields & remaining will have default values.

Inspect the returned type by calling .getClass() on a returned object. I'd guess it's an array.

But this is not really a good way to use JPA. Select the whole entity and then just don't use what you don't need. It's not such a performance hit.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!