あなたの例は単なるネイティブSQLであり、HQLではありません。とにかく、Criteria APIの次のメソッドを使用して、目的のCriteriaオブジェクトを作成できます。
たとえば、SQLが次の場合:
select
TableA.columnA ,TableB.columnB ,TableC.columnC
from TableA
inner join TableB on TableA.tableB_id=TableB.id
inner join TableC on TableA.tableC_id=TableC.id
where TableA.columnAA="AAA"
and TableB.columnBB="BBB"
and TableC.columnCC="CCC"
その場合、Criteriaオブジェクトは次のようになります。
List<Object[]>resultList= (List<Object[]>)session.createCriteria(TableA.class, "aliasOfTableA")
.add(Restrictions.eq("aliasOfTableA.columnAA", "AAA"))
.createCriteria("aliasOfTableA.tableBId" , "aliasOfTableB")
.add(Restrictions.eq("aliasOfTableB.columnBB", "BBB"))
.createCriteria("aliasOfTableA.tableCId" , "aliasOfTableC")
.add(Restrictions.eq("aliasOfTableC.columnCC", "CCC"))
.setProjection( Projections.projectionList()
.add( Projections.property("aliasOfTableA.columnA") )
.add( Projections.property("aliasOfTableB.columnB"))
.add( Projections.property("aliasOfTableC.columnC") )
).list();
for (Object[] obj : resultList) {
System.out.println(obj[0]); //print the value from TableA.columnA
System.out.println(obj[1]); //print the value from TableB.columnB
System.out.println(obj[2]); //print the value from TableC.columnC
}
Criteria
のすべてのパラメータは、マップされたJavaエンティティのプロパティ名とクラス名を使用することに注意してください。