Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » CriteriaBuilder.quot of two SUM expression get wrong javaType and cant reach the correct constructor
CriteriaBuilder.quot of two SUM expression get wrong javaType and cant reach the correct constructor [message #1742228] Wed, 31 August 2016 22:52
Eclipse UserFriend
Hi,

On EclipseLink version 2.6.3 I got the exception:
Quote:

java.lang.IllegalArgumentException: An exception occurred while inspecting class class com.example.ContainerSumOfProductByPerson for a
constructor using selection criteria types as arguments. If this CriteriaQuery was not intended to be a constructor query
please verify that the selection matches the return type.


executing this code:
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        ParameterExpression<Company> pCompanyParameterExpression = cb.parameter(Company.class, "pCompany");
        ParameterExpression<Person> pPersonParameterExpression = cb.parameter(Person.class, "pPerson");
        ParameterExpression<ProductBase> pProductBaseParameterExpression = cb.parameter(ProductBase.class, "pProductBase");
        ParameterExpression<ProductVariant> pProductVariantParameterExpression = cb
                .parameter(ProductVariant.class, "pProductVariant");
        ParameterExpression<Integer> pStatusParameterExpression = cb.parameter(Integer.class, "pStatus");
        CriteriaQuery qSumOfProductByPerson = cb.createQuery(ContainerSumOfProductByPerson.class);
        Root<PaymentItem> sPaymentItem = qSumOfProductByPerson
                .from(PaymentItem.class);
        sPaymentItem.alias("sPaymentItem");
        Join sOrderItem = sPaymentItem.join("orderItem");
        sOrderItem.alias("sOrderItem");
        Join sOrder = sOrderItem.join("order");
        sOrder.alias("sOrder");
        Join sClassification = sOrder.join("classification");
        sClassification.alias("sClassification");
        Join sField = sClassification.join("field");
        sField.alias("sField");
        Join sRelationshipField = sField.join("relationshipField");
        sRelationshipField.alias("sRelationshipField");
        Join sInvoiceItemPayment = sPaymentItem.join("invoiceItemPayment");
        sInvoiceItemPayment.alias("sInvoiceItemPayment");
        Join sInvoiceDistribution = sInvoiceItemPayment.join("invoiceDistribution");
        sInvoiceDistribution.alias("sInvoiceDistribution");
        Join sOrderDistribution = sInvoiceDistribution.join("orderDistribution");
        sOrderDistribution.alias("sOrderDistribution");
        Join sPaymentPerson = sOrderDistribution.join("paymentPerson");
        sPaymentPerson.alias("sPaymentPerson");
        Join sPaymentRegistry = sPaymentPerson.join("paymentRegistry");
        sPaymentRegistry.alias("sPaymentRegistry");
        Expression quantity = cb.sum(sPaymentItem.get("quantity").as(Integer.class));
        qtd.alias("qtd");
        Expression vlr = cb.sum(sPaymentItem.get("paymentValue").as(Double.class));
        vlr.alias("vlr");
        Expression qtdQuotByVlr = cb.quot(qtd.as(Integer.class), vlr.as(Double.class)).as(Double.class);
        qtdQuotByVlr.alias("qtdQuotByVlr");
        qSumOfProductByPerson.select(
            cb.construct(
                ContainerSumOfProductByPerson.class,
                sPaymentRegistry.get("number"), 
                sPaymentRegistry.get("registeredDate"), 
                sField.get("number"),
                sRelationshipField.get("code"), 
                qtd, 
                vlr, 
                qtdQuotByVlr
            )
        );
        Predicate whereCriteria = cb.conjunction();
        whereCriteria = cb.and(whereCriteria,
                cb.equal(sPaymentItem.get("hasOff"), cb.literal(Boolean.FALSE)));
        whereCriteria = cb.and(whereCriteria, cb.equal(sOrderItem.get("ProductBase"), pProductBaseParameterExpression));
        whereCriteria = cb.and(whereCriteria,
                cb.equal(sOrderItem.get("ProductVariant"), pProductVariantParameterExpression));
        whereCriteria = cb.and(whereCriteria, cb.equal(sPaymentRegistry.get("mainPerson"), pPersonParameterExpression));
        whereCriteria = cb.and(whereCriteria, cb.equal(sPaymentRegistry.get("company"), pCompanyParameterExpression));
        whereCriteria = cb.and(whereCriteria, cb.equal(sPaymentRegistry.get("status"), pStatusParameterExpression));
        qSumOfProductByPerson.where(whereCriteria);
        qSumOfProductByPerson.groupBy(sPaymentRegistry.get("number"),
                sPaymentRegistry.get("registeredDate"), sField.get("number"), sRelationshipField.get("code"));
        qSumOfProductByPerson.orderBy(cb.asc(sPaymentRegistry.get("registeredDate")));


The problem occurs, at line when qSumOfProductByPerson.select method got called at runtime, the stack trace off EclipseLink that throws above excpetion is:

  
    org.eclipse.persistence.internal.jpa.querydef.CriteriaQueryImpl.populateAndSetConstructorSelection(CriteriaQueryImpl.java:413)
    org.eclipse.persistence.internal.jpa.querydef.CriteriaQueryImpl.select(CriteriaQueryImpl.java:93)
    ...


after some debug, I see that the qtdQuotByVlr that is a quot expression, dont have the javaType defined, and inside of populateAndSetConstructorSelection
that was used as null, because of that PrivilegedAccessHelper.getConstructorFor cant reach the correct constructor of class ContainerSumOfProductByPerson.

As you can see above I tried to put .as(Double.class) in a way to try a workaround for this, but without success.

My doubt now is if this is a BUG, or I make some mistake in above Criteria construction that dont tell the correct type? If this is a BUG, what is better place
that developers think to solve this, maybe I can solve, and arange a patch when filling the BUG, if that is the case.
Previous Topic:news.eclipse.org is shutting down.
Next Topic:EclipseLink + Stream + Java 8
Goto Forum:
  


Current Time: Sat Jul 05 04:31:31 EDT 2025

Powered by FUDForum. Page generated in 0.05362 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top