2 Replies Latest reply: Dec 11, 2012 11:50 PM by 979257 RSS

    NamedNative query is throwing error 'missing discriptor'


      I want to execute a Query as "select DISTINCT productName, version from product where productGroup = :prodGroup". There is an entity configured as ProductRelations. I want to fetch this information from my JavaServiceFacade.
      I have created a simple serialized DTO object as ProductType (productName, version) and using this as the result class.
      The entity class is product.java. In my case, I dont want my service to return the entity object.

      If I try the resultClass as product.java, this will not work, as I am not returning a primary key. I cannot use the primary key to get the DISTINCT of productName and versions :(

      name = "findAllDistinctProducttypes",
      query = "select distinct o.name, o.revision from product o where o.prodGroup = ?",
      hints = {@QueryHint(name = "toplink.cache-usage", value="DoNotCheckCache")},
      resultSetMapping = "producttypes",
      resultClass = project1.ProductType.class

      From the service facade class
      public List<ProductType> getProductByName(String productName) {
      List<ProductType> productList = (List<ProductType>) getEntityManager().createNamedQuery("findAllDistinctProducttypes").setParameter(1,productName).getResultList(); //qry.getResultList();

      when I run the above code, it is throwing me an exception as

      Exception in thread "main" Local Exception Stack:
      Exception [EclipseLink-6007] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.QueryException
      Exception Description: Missing descriptor for [class project1.ProductType].
      Query: ReadAllQuery(name="findAllDistinctProducttypes" referenceClass=ProductType sql="select distinct o.name, o.revision from Lhproduct o where o.name = ?")
           at org.eclipse.persistence.exceptions.QueryException.descriptorIsMissing(QueryException.java:438)
           at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkDescriptor(ObjectLevelReadQuery.java:748)
           at org.eclipse.persistence.queries.ObjectLevelReadQuery.prePrepare(ObjectLevelReadQuery.java:2063)
           at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrePrepare(ObjectLevelReadQuery.java:836)
           at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:819)
           at org.eclipse.persistence.queries.DatabaseQuery.prepareCall(DatabaseQuery.java:1588)
           at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:568)
           at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1001)
           at project1.JavaServiceFacade.getProductByName(JavaServiceFacade.java:151)
           at project1.JavaServiceFacade.main(JavaServiceFacade.java:34)

      Please help, how to resolve this issue. I
      return productList;
        • 1. Re: NamedNative query is throwing error 'missing discriptor'

          I think I found the solution.
          There is a way to use the NEW keyword in constructing the query, which helps returning non-entity objects.
          What I did

          public List<ProductType> getProductByName(String productName) {
          String sqlQuery = "select DISTINCT *NEW* project1.ProductType(o.name, o.revision) from product o where o.name = :prodname";
          Query qry = getEntityManager().createQuery(sqlQuery);
          return qry.getResultList();
          The ProductType is a non-entity object, a simple plain object implementing Serialiabale. But you need to define the appropriate constructor.

          Happy coding :-)

          Thanks and Regards,
          • 2. Re: NamedNative query is throwing error 'missing discriptor'
            To get the non-entity resultset out of a entitymanager.createQuery method using JPA, construct the query with the NEW method and make a call using entityManager.createQuery(...)