Announcement Announcement Module
No announcement yet.
How to retrieve the ids of entities using Specification Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to retrieve the ids of entities using Specification

    I am currently using a repository that I have created by extending "edu.wgu.pcv.domain.repository.JpaRepository" and enabling jpa repositories. I pass in a in order to filter data. However, I would also like a way to be able to only retrieve the entities ids as a result List instead of returning the entities. I know that I could retrieve a list of the entities and then loop through them to get all the ids, but it seems to be overkill to retrieve the whole entity when all you need is the id (a simple Long).

  • #2
    Criteria Queries is a way to solve this problem. One option to select single/multiple values is by selecting an array (Object[]).
    Another is to create a wrapper Object that the criteria builder will use in constructing the results of the query.
    Another option the Tuple criteria is a good option for your use case, this option uses the javax.persistence.Tuple interface, see links below to documentation on example code to implement these options