hibernate selecting sum of few Entity fields
-
19-10-2022 - |
Question
I am trying to get from db only a few columns sum. I dont wonna download whole record (entity) but only few columns from whole table. And I dont wanna many records of them. I just one to have a sum. I have something like that:
TypedQuery sumsOfSharedMeters = (TypedQuery) JPA
.em()
.createNativeQuery(
"SELECT "
+ " SUM(wszysUruchProc), SUM(wszysProcToku), SUM(wszysWykoProc), SUM(wszysPrzeterProc), "
+ " SUM(wszysPowtPrzeterProc), SUM(zgloszNiezgodDoRejNiezgod), SUM(niezgodWykryteAudWew), SUM(l4), SUM(nz) "
+ " FROM ZycieBiuro_WorkerMonthReport E WHERE year=:year "
+ " AND intmonth=:month ")
.setParameter("year", year)
.setParameter("month", month);
Object results = sumsOfSharedMeters.getSingleResult();
But I am getting an object wich is an: Ljava.lang.Object;@621aba
but no usefull data. Please help
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow