-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Named JPQL Query and Native SQL Query produce different SUMs
PostPosted: Thu Nov 27, 2014 6:01 am 
Newbie

Joined: Thu Nov 27, 2014 5:47 am
Posts: 1
Hello everybody.

i'm dealing with the following scenario:

The Entity Class:
Code:
...
@NamedQuery(
            name = "Table.getSum",
            query = "SELECT SUM(s.price) FROM Table s WHERE
(s.openingDate >= :openingDate AND s.closingDate <= :closingDate)"
)
...


The EJB:
Code:
...
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:
Quote:
SELECT SUM(price) FROM Table WHERE openingDate >= 'YYYY-01-01T00:00:00' AND closingDate <= 'YYYY-12-31T23:59:59'


But the two sums are of by a significant amount. That drives me crazy. How can that be?

I'm using hibernate 4.3.7 with wildfly 8.2.0 and the current mariadb on centos 7.


Thank you very much for any suggestion.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.