List of usage examples for org.hibernate Criteria setResultTransformer
public Criteria setResultTransformer(ResultTransformer resultTransformer);
From source file:de.iteratec.iteraplan.persistence.dao.GenericBaseDAO.java
License:Open Source License
/** {@inheritDoc} */ @SuppressWarnings("unchecked") public List<E> loadElementListWithIds(final Set<T> identifiers) { if ((identifiers == null) || identifiers.isEmpty()) { return new ArrayList<E>(); }/*from ww w . j a va2 s. c o m*/ HibernateCallback<List<E>> callback = new HibernateCallback<List<E>>() { public List<E> doInHibernate(Session session) { Criteria c = session.createCriteria(getPersistentClass()); c.add(CriteriaUtil.createInRestrictions("id", identifiers)); c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return c.list(); } }; return getHibernateTemplate().executeFind(callback); }
From source file:de.iteratec.iteraplan.persistence.dao.GenericBaseDAO.java
License:Open Source License
/** * {@inheritDoc}//from w ww.j a v a 2s . co m */ @SuppressWarnings("unchecked") public List<E> loadFilteredElementList(final String property, final Set<T> excludedIds) { HibernateCallback<List<E>> callback = new HibernateCallback<List<E>>() { public List<E> doInHibernate(Session session) { Criteria c = session.createCriteria(getPersistentClass()); if ((excludedIds != null) && !excludedIds.isEmpty()) { c.add(CriteriaUtil.createNotInRestrictions("id", excludedIds)); } if (property != null) { c.addOrder(Order.asc(property)); } // without this for some reason multiple instances may be returned, // for example when loading AttributeTypeGroup. Strangely enough, when // loading AttributeTypeGroups by the HQL query "from AttributeTypeGroup", // only distinct instances are returned ?! Note that the distinct part is // done programatically by the Criteria implementation, not by the database! c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return c.list(); } }; return getHibernateTemplate().executeFind(callback); }
From source file:de.powerstaff.business.dao.hibernate.FreelancerDAOHibernateImpl.java
License:Open Source License
@Override public List<ProjectPosition> findPositionsFor(final Freelancer aFreelancer) { return (List<ProjectPosition>) getHibernateTemplate().execute(new HibernateCallback<Object>() { @Override//from w ww.j av a2s. c om public Object doInHibernate(Session aSession) throws HibernateException, SQLException { ArrayList<ProjectPosition> theResult = new ArrayList<ProjectPosition>(); Criteria theCriteria = aSession.createCriteria(ProjectPosition.class); theCriteria.add(Restrictions.eq("freelancerId", aFreelancer.getId())); theCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); theResult.addAll(theCriteria.list()); Collections.sort(theResult); return theResult; } }); }
From source file:de.powerstaff.business.dao.hibernate.ProjectDAOHibernateImpl.java
License:Open Source License
@Override public Collection<SavedProfileSearch> getSavedSearchesFor(final Project aProject) { return (Collection<SavedProfileSearch>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session aSession) { Criteria theCriteria = aSession.createCriteria(SavedProfileSearch.class); theCriteria.add(Restrictions.eq("project", aProject)); theCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return theCriteria.list(); }/* w ww . j av a 2 s . c om*/ }); }
From source file:de.powerstaff.business.dao.hibernate.ProjectDAOHibernateImpl.java
License:Open Source License
@Override public List<Project> findProjectsFor(final Customer aCustomer) { return (List<Project>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session aSession) { Criteria theCriteria = aSession.createCriteria(Project.class); theCriteria.add(Restrictions.eq("customer", aCustomer)); theCriteria.addOrder(Order.asc("projectNumber")); theCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return theCriteria.list(); }//from w w w . j a v a 2 s .c om }); }
From source file:de.powerstaff.business.dao.hibernate.ProjectDAOHibernateImpl.java
License:Open Source License
@Override public List<Project> findProjectsFor(final Partner aPartner) { return (List<Project>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session aSession) { Criteria theCriteria = aSession.createCriteria(Project.class); theCriteria.add(Restrictions.eq("partner", aPartner)); theCriteria.addOrder(Order.asc("projectNumber")); theCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return theCriteria.list(); }//from w ww . j a va 2s . com }); }
From source file:de.visualdependencies.data.dao.impl.AbstractGeneralDaoImpl.java
License:Open Source License
protected Criteria createCriteria() { final Session session = sessionFactory.getCurrentSession(); final Criteria criteria = session.createCriteria(getPersistentClass()); // If an entity has any mapped collection with eager loading, this will avoid multiple result tuples. // See: https://forum.hibernate.org/viewtopic.php?f=25&t=988655 criteria.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); return criteria; }
From source file:debop4k.data.orm.hibernate.dao.HibernateDao.java
License:Apache License
private <P> Criteria buildProjectionCriteria(@NonNull Class<P> projectClass, @NonNull Criteria criteria, @NonNull Projection projections, boolean distinctResult) { if (distinctResult) criteria.setProjection(Projections.distinct(projections)); else//from ww w . j ava2 s. co m criteria.setProjection(projections); return criteria.setResultTransformer(Transformers.aliasToBean(projectClass)); }
From source file:ecommerce.dao.Dao.java
public List<T> listar() { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*from w w w .j a v a 2 s . co m*/ Criteria criteria = session.createCriteria(classe); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<T> lista = criteria.list(); session.getTransaction().commit(); return lista; }