ezhovdv
9/28/2016 - 9:11 AM

Hibernate named query POJO transformation

Hibernate named query POJO transformation

public List<IngredientUsage> summary(final UsageContext context, final boolean isGlobal) {
	final Session session = isGlobal ? sessionFactory.getCurrentSession()
			: sessionFactorySyncBase.getCurrentSession();
	final Query q = session.getNamedQuery(PRICE_REPORT);
	q.setParameter(IngredientByOrder.P_USER_ID, context.getUserId())
		.setParameter(IngredientByOrder.P_START, context.getStart())
		.setParameter(IngredientByOrder.P_FINISH, context.getFinish());
	q.setResultTransformer(new AliasToBeanResultTransformer(IngredientUsage.class));
	return DaoUtils.listAndCast(q);
}