List of usage examples for org.hibernate SQLQuery setResultTransformer
@Deprecated Query<R> setResultTransformer(ResultTransformer transformer);
From source file:view.AdminCarouselView.java
@PostConstruct public void init() { Session session = null;//from www. ja v a 2s . c o m Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Criteria cr = session.createCriteria(Festival.class); cr.addOrder(Order.desc("brojPregleda")); cr.setMaxResults(5); List result = cr.list(); mostViewFestivals = (List<Festival>) result; String sql = "SELECT F.naziv AS nazivFestivala, F.datumVremeOd, F.datumVremeDo, F.mesto, F.prosecnaOcena, F.cenaPaket, F.cenaDan, F.brojPregleda, SUM(R.brojUlaznica) AS brojProdatihUlaznica " + "FROM festival F, rezervacija R " + "WHERE R.idFest = F.idFest " + "AND R.status = 'kupljeno' " + "GROUP BY F.naziv " + "ORDER BY brojUlaznica DESC " + "LIMIT 5;"; SQLQuery query = session.createSQLQuery(sql); query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); mostBuyedFestivals = query.list(); } catch (Exception ex) { if (tx != null) tx.rollback(); ex.printStackTrace(); } finally { if (tx != null) tx.commit(); session.close(); } }