Hibernate criteria to fetch Data from 3 table's + Sum of a Specific Column and also group by a column name.

738 Views Asked by At

I want to use Hibernate criteria to fetch Data from 3 table's + Sum of a Specific Column and also group by a column name.

Table 1 Table 2 Table 3

1.) Select Some of the Columns in table 1, table 2, table 3 2.) sum of a Particular column 3.) Group By on a specific column

It will be helpful if I can write Criteria for this.

1

There are 1 best solutions below

0
On

I wrote down the criteria myself,

List result = session.createCriteria(Table1.class)

.createAlias("Table2", "Tb2")
.createAlias("Table3", "Tb3")
.add( Restrictions.eqProperty("Tb2.someColumn", "some Property from Model") )
 .setProjection( Projections.projectionList()
     .add( Projections.avg("someproperty") )
    .add( Projections.max("someproperty") )
    .add( Projections.groupProperty("someproperty") )
)
.list();

Felt like it will be useful to others like me...