jpa - JPQL Aggregation return -
lets have following jpql query
select e.column1, e.column2, sum(e.column3), sum(e.column4) entity e group e.column1, e.column2
obviously wont returning entity object bit more complex. how return in method?
public list<???> query1() { query q = entitymanager.createquery("..."); list<something???> list = q.getresultlist(); return list; }
such query returns list<object[]>, each element array of objects. first element of array have type of entity.column1, second 1 have type of entity.column2, , last 2 ones (with hibernate @ least) of type long (check eclipselink).
it's transform list<object[]> in list<foo>, looping on list of objects , transforming each 1 foo. may use constructor notation directly in query (provided foo has such constructor), dislike it, because isn't refactorable:
select new com.baz.bar.foo(e.column1, e.column2, sum(e.column3), sum(e.column4)) ...
Comments
Post a Comment