Hi,
You can use Hibernate Criteria queries with ResultTransformers.
Here's an example.
Criteria criteria = session.createCriteria(Car.class) ; criteria.setProjection( Projections.projectionList() .add(Property.forName("name").as("name")) .add(Property.forName("make").as("make")) ).setResultTransformer(new AliasToBeanResultTransformer(Car.class)); criteria.list() ;
Assume, Car has many more fields like top_speed, max_power etc. and user wants only name and make.
It is dynamic. Populate the projection list as per user preferences at run time.
The same can be realized using,
i) HQL Report queries.
ii) Native SQL queries.
ResultTransformer is not mandatory. You can omit it if are okay with handling object arrays.
----------------------------------------------------
Rate the reply if you find it helpful
|