java - JPA Summary entity or meta entity -


i'm using jpa (with hibernate under hood) , want select out bunch of data summarises set of real entities, instance name, name of parent entity , count of instances name.

in entirely fictional example lets have entity called ticket, has parent entity named category has parent entity called metacategory.

i want retrieve list of categories, , display parent metacategory name, category name, , count of tickets within category.

i select tickets , shove them in hashset, keyed category, feels quite inefficient. i'd ideally select out list of entirely new entity, not backed database table, holds metacategory, category , integer of count of tickets...

is possible using jpa, specificaly using criteriabuilder? have select things out manually?

if absolutely need use criteria queries, can using criteria constructors , selection items see criteriaquer#multiselect

you have use select specific columns interested in , tuple or object array query.

for instance, tuple (not tested @ all) :

criteriabuilder cb = em.getcriteriabuilder(); criteriaquery<tuple> query = cb.createquery(integer.class);  root<category> r = query.from(category.class); join<category, ticket> jt = r.join("tickets") query.multiselect (  cb.construct(a.class, root.get("property1"), root.get("property2"),  cb.construct(ticket.class, jt.get("...")) ); list<tuple> result = query.getresultlist(); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -