hibernate - Named JPQL Query and Native SQL Query produce different SUMs -
i'm dealing following scenario:
the entity class:
@namedquery( name = "table.getsum", query = "select sum(s.price) table s (s.openingdate >= :openingdate , s.closingdate <= :closingdate)" )
the ejb:
calendar openingdate = new gregoriancalendar(year, 1, 1, 0, 0, 0); calendar closingdate = new gregoriancalendar(year, 12, 31, 23, 59, 59); bigdecimal salepricesum = em.createnamedquery("table.getsum", bigdecimal.class) .setparameter("openingdate", openingdate) .setparameter("closingdate", closingdate) .getsingleresult();
the native sql query:
select sum(price) table openingdate >= 'yyyy-01-01t00:00:00' , closingdate <= 'yyyy-12-31t23:59:59'
but 2 sums of significant amount. drives me crazy. how can be?
i'm using hibernate 4.3.7 wildfly 8.2.0 , current mariadb on centos 7.
thank suggestion.
month
parameter in constructor gregoriancalendar
zero-based, messing results. docs:
month - value used set month calendar field in calendar. month value 0-based. e.g., 0 january.
Comments
Post a Comment