Karthik
Karthik

Reputation: 51

Hibernate hql query used with sum() function returning null values

Hi i tried to execute this query it running properly in mysql database . by using hibernate its returning null value can you explain me thanks in advance by karthik

string = "SELECT sum(feed1Consumed),sum(feed2Consumed)"
         + "FROM com.ebiodata.upstream.pojo.UpstreamMammalianFermentationTempUpdate"
         + " where upstreamHeader.id=\'" + serializableId + "\'";

Upvotes: 0

Views: 4945

Answers (1)

Johanna
Johanna

Reputation: 5303

sum() returns null if the summed value is null for all summed rows or if there are no rows found.

In hibernate.cfg.xml you can use <property name="show_sql">true</property> to see the SQL statement which is generated by hibernate.

I don't understand why you compare the id as a string. serializableId probably is a number. You can do a numeric comparison with

" where upstreamHeader.id=" + serializableId;

Upvotes: 1

Related Questions