2012-03-27 3 views
0

Wie schreibe ich ein Kriterium für SQL folgendeVerknüpfungskriterien mit Gruppe

SELECT 
m.match_type, 
count(m.match_type) 
cat.description, 
loc.oid 

FROM 
USER_MATCH m, 
RECORD rec, 
CATEGORY cat, 
LOCATION loc 

WHERE 
m.record_oid = rec.oid and 
rec.category_oid = cat.oid and 
rec.location_oid = loc.oid 
group by m.match_type, cat.description, loc.oid 

Ich versuche es haben, wie folgend, aber ich bin immer subquery Ausdrücke hier Fehler nicht erlaubt.

Criteria criteria = hibernateTemplate.getSessionFactory().getCurrentSession().createCriteria(Match.Class); 
criteria.createAlias("record", "record"); 
criteria.createAlias("category", "category"); 

ProjectionList projList = Projections.projectionList();   
projList.add(Projections.groupProperty("record.categoryId")); 
projList.add(Projections.groupProperty("record.locationId")); 
criteria.setProjection(projList); 

Dank im Voraus :)

Antwort

0

Dies wird Ihnen helfen

Criteria criteria = hibernateTemplate.getSessionFactory().getCurrentSession().createCriteria(Match.Class); 
criteria.createAlias("record", "record"); 
criteria.createAlias("category", "category"); 
criteria.createAlias("location", "location"); 

ProjectionList projList = Projections.projectionList(); 
projList.add(Projections.groupProperty("match_type"));  
projList.add(Projections.count("match_type"); 
projList.add(Projections.groupProperty("record.categoryId")); 
projList.add(Projections.groupProperty("record.locationId")); 
criteria.setProjection(projList); 

Hinweis, die Sie nicht aufnehmen müssen Zustand in den Ruhezustand kommen, weil diese automatisch von Create handeled wird.