Doubt regarding JPA namedquery

后端 未结 2 1445
暗喜
暗喜 2020-12-22 05:49

I am trying to execute a namedquery

@NamedQuery(name=\"getEmployeeDetails\",query=\"select e.username,e.email,e.image,e.firstname,e.lastname from Employee e         


        
相关标签:
2条回答
  • 2020-12-22 06:28

    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.

    0 讨论(0)
  • 2020-12-22 06:29

    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.

    0 讨论(0)
提交回复
热议问题