2012-03-27 3 views
0

を基準に参加私はSQLグループ

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 

を以下の基準を作成するにはどうすればよい私は以下のが、私はここでエラーが許可されていない サブクエリ式を取得していて、それをしようとしています。事前に

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); 

感謝:)

答えて

0

これは、これは自動的にCreateALiasによってhandeledますので、あなたが休止状態で結合条件を含める必要はありません注あなた

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); 

のに役立ちます。