1 Reply Latest reply: Apr 26, 2012 1:32 PM by Cdelahun-Oracle RSS

    JPA  using native query - distinct

    java4ever
      I am stuck with a issue where in i want to use the the native query feature of JPA to get distinct rows of data.
      Query aQuery = getEntityManager().createNativeQuery("select distinct name from table",Myclass);
      return aQuery.getResultList();
      I have tried it and it's not working for me can some kindly suggest how to do this

      Info: My backend is Oracle 10g and Appserver is Weblogic10gR2 and iam using openjpa 1.1


      Thanks in adv.
      VR
        • 1. Re: JPA  using native query - distinct
          Cdelahun-Oracle
          createNativeQuery("select distinct name from table",Myclass);
          states that you are trying to build an entity of Type Myclass for each returned row, but the SQL used is only returning a name. If all you want is the name field data, try:
          getEntityManager().createNativeQuery("select distinct name from table").getResultList();
          which will return a list containing arrays representing the data for each row - which will be just the name field data.

          If you are still getting openJPA problems you might try posting on a openJPA forum, or try using TopLink/EclipseLink as the JPA provider and posting the exception here.

          Best Regards,
          Chris