Type problem with Projectionlist in criteria

Asked

Viewed 44 times

0

I’m having a problem in java giving the following error:

in class: com.app.myApp.ReportDTO, setter method of property: indicator
expected type: java.lang.Double, actual value: java.lang.IntegerInteger

Which occurs in my criteria, when creating a projector, setando a projection as SUM:

projectionList.add(Projections.sum(propertyIndicator), "indicator");

By giving the criteria.List(); the error is popped. The strange thing is that when I used avg function, instead of sum, it worked normally, without error.

From what I’ve seen, the error occurs because my propertyIndicator is a Integer, and the Property "indicator" is a Double. I can perform the conversion of these properties in the function sum?

  • What parameters projectionList.add accepted?

  • it accepts several parameters, the problem is that sum vc puts the string with the name of the property, that this can be any type of parameter. That’s why you couldn’t do a conversion inside the sum

1 answer

1


Could not make explicit conversion inside the Projections.sum, so I had to go in search of other resources, and I changed the Setter of my DTO to receive a Integer as parameter, and within it do the conversion of the property to double:

public void setIndicator(Integer indicator) {
        if (indicator != null) {
            this.indicator = Double.valueOf(indicator.doubleValue());
        } else {
            this.indicator = null;
        }
    } 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.