Search code examples
listuniqueopenjpa

Need a unique List of JPA entites


I am attempting to get a unique List of JPA entities... I can't do it by adding a Distinct clause in the named query because I will be adding these entities to a list from multiple entities. So I decided to do the uniqueness inside the code... Using eclipse and some OpenJPA tools I have added a default hashCode and an Equlas Method to the Entity Bean...

After doing that I created an ArrayList, And added all entity objects to it I do the following...

return new ArrayList(new HashSet(personListRetVal));

I think that should return a unique list... Any advice? How can I return an ordered unique List?


Solution

  • Perhaps you want to use a LinkedHashSet?