0

I am using hibernate 5.2 and java 8

i have a situation where i am using hql to do the following, where from and to are LocalDateTime objects passed in the method:

Query buyQuery = session
            .createQuery("SELECT sum(price * quantity) FROM Transaction where transactionType='buy' and transactionDateTime between :from and :to");
    buyQuery.setParameter("from", from);
    buyQuery.setParameter("to", to);
sb.setTotalPurchases((Double) buyQuery.getSingleResult());

Hibernate 5.2 says that it has native support for these date objects so I don't think it is that issue however i get a null pointer exception, when trying to set sb because the query returns null.

My HQL is rusty (i normally use the criterion api) so my question is does the hql look right and if so can anyone point me to the source of my issues?

Thanks :)

user1383163
  • 577
  • 1
  • 7
  • 24
  • Are you sure that the query returns null? Have a debugged and inspected the return value from query? where and how did you define `sb`? – Mubin Jul 09 '16 at 22:34
  • sb is a object i use to store the query result, the object is built up in this way and evetually stuck through jackson to be used to send json to the client. – user1383163 Jul 09 '16 at 23:11
  • Can you update your question with the generated SQL as well as the actual stacktrace of the NullPointerException? – Naros Jul 10 '16 at 16:11

0 Answers0