Search code examples
openjpa

DistinctResultList in OpenJPA


I am attempting to get a distinct list of id's back that would be longs... But I am getting back this DistinctResultList... How can one handle this so that they get back results they are expecting... Here is what I am doing...

@NamedQuery(name="getProvidersByResourceIds", query = "SELECT DISTINCT p.resourceId FROM Provider p WHERE p.resourceId `in :resourceIds")`

Out of that I try and get the resourceIds' by doing this...

List<Long> provIDs = (List<Long>) emf.createNamedQuery("getProvidersByResourceIds").setParameter("resourceIds", values).getResultList();

But like I said, I keep getting back a DistinctResultList... Looking through the debugger, I can see the values I am getting back. How can I translate this into something usefull?

javax.ejb.EJBException: See nested exception; nested exception is: java.lang.IllegalArgumentException: Parameter "Parameter<long>('resourceIds')" declared in "SELECT p FROM Provider p WHERE p.resourceId = :resourceIds" is set to value of "org.apache.openjpa.kernel.DistinctResultList@35fb35fb" of type "org.apache.openjpa.kernel.DistinctResultList", but this parameter is bound to a field of type "long".
java.lang.IllegalArgumentException: Parameter "Parameter<long>('resourceIds')" declared in "SELECT p FROM Provider p WHERE p.resourceId = :resourceIds" is set to value of "org.apache.openjpa.kernel.DistinctResultList@35fb35fb" of type "org.apache.openjpa.kernel.DistinctResultList", but this parameter is bound to a field of type "long"

Solution

  • Change your query to :

    @NamedQuery(name="getProvidersByResourceIds", 
        query = "SELECT DISTINCT p.resourceId FROM Provider p WHERE p.resourceId in (:resourceIds)");