Example usage for org.hibernate Criteria setResultTransformer

List of usage examples for org.hibernate Criteria setResultTransformer

Introduction

In this page you can find the example usage for org.hibernate Criteria setResultTransformer.

Prototype

public Criteria setResultTransformer(ResultTransformer resultTransformer);

Source Link

Document

Set a strategy for handling the query results.

Usage

From source file:com.usetheindexluke.FewerColumnsHibernate.java

License:Creative Commons License

public static void main(String[] args) {
    Session session = new Configuration().configure().buildSessionFactory().openSession();
    try {//from   w w  w  . j  a v a 2 s.c  o  m
        Criteria q = session.createCriteria(Sales.class, "sales");
        q.add(Restrictions.gt("saleDate", getSixMonthAgo()));
        q.createAlias("employee", "employee");
        q.setProjection(Projections.projectionList().add(Projections.property("sales.saleDate"), "saleDate")
                .add(Projections.property("sales.eurValue"), "eurValue")
                .add(Projections.property("employee.lastName"), "lastName")
                .add(Projections.property("employee.firstName"), "firstName"));
        q.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);

        List<Map> result = q.list();

        for (Map s : result) {
            String txt = " Employee: " + s.get("lastName") + " date: " + s.get("saleDate") + " EUR value: "
                    + s.get("eurValue");
            // System.out.println(txt);
        }
    } finally {
        session.close();
    }
}

From source file:com.ust.coppel.incentivos.repository.impl.IncReglasNegocioRepositoryImpl.java

@Transactional
@Override/*from   w w  w .j a v a 2  s  .  c  o  m*/
public List<IncReglasNegocio> findAll(IncGruposReglas grupos) {
    Session session = sessionFactory.getCurrentSession();

    Criteria criteria = session.createCriteria(IncReglasNegocio.class);

    criteria.add(Restrictions.eq("incGruposReglas.iduGrupo", grupos.getIduGrupo()));
    criteria.add(Restrictions.ne("clvEstatus", 9));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List<IncReglasNegocio> aux = criteria.list();

    return aux;
}

From source file:com.ust.coppel.incentivos.repository.impl.IncVariablesGlobalesRepositoryImpl.java

@Transactional
@Override/*from   w w w.  j  av a2s . c o m*/
public List<IncVariablesGlobales> findAll(IncPaqueteReglas paq_) {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(IncVariablesGlobales.class);

    criteria.add(Restrictions.eq("incPaqueteReglas.iduPaquete", paq_.getIduPaquete()));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    List<IncVariablesGlobales> incVentasPorGerentesProgc = criteria.list();

    return incVentasPorGerentesProgc;
}

From source file:com.ut.tekir.invoice.yeni.LimitationChecker.java

License:LGPL

@SuppressWarnings("unchecked")
public void getPrices() {

    HibernateSessionProxy session = (HibernateSessionProxy) getEntityManager().getDelegate();

    Criteria ecrit = buildCriteriaForWarehouse().getExecutableCriteria(session);
    ecrit.setCacheable(true);//w ww.  jav  a  2  s. co m
    ecrit.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    warehouseResult = ecrit.list();
    calculateSummary();

}

From source file:com.ut.tekir.report.AccountStatusReportBean.java

License:LGPL

@SuppressWarnings("unchecked")
public void executeReport() {

    HibernateSessionProxy session = (HibernateSessionProxy) getEntityManager().getDelegate();

    Criteria ecrit = buildCriteria().getExecutableCriteria(session);
    //ecrit.setCacheable(true);
    //ecrit.setResultTransformer(new AliasToBeanResultTransformer(AccountStatusModel.class));
    ecrit.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    setResultList(ecrit.list());//from  w w w .  j  ava 2s  .  co m

    log.debug("Result : #0", getResultList());

    calculateSummary();
}

From source file:com.ut.tekir.report.ContactStatusReportBean.java

License:LGPL

@SuppressWarnings("unchecked")
public void executeReport() {
    HibernateSessionProxy session = (HibernateSessionProxy) getEntityManager().getDelegate();

    Criteria ecrit = buildCriteria().getExecutableCriteria(session);
    //ecrit.setCacheable(true);
    //ecrit.setMaxResults( 100 );
    ecrit.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    reportResult = ecrit.list();/* w  ww. ja  v  a  2s  .c  o m*/
    calculateSummary();
}

From source file:com.ut.tekir.stock.ProductTxnReportBean.java

License:LGPL

@SuppressWarnings("unchecked")
public void getPrices() {

    if (this.filterModel.isEmpty()) {
        facesMessages.add("Ltfen en az bir alan doldurunuz.");
        return;//from   w w  w . ja  v  a 2  s  .co  m
    }

    HibernateSessionProxy session = (HibernateSessionProxy) getEntityManager().getDelegate();

    Criteria ecrit = buildCriteriaForPrice(TradeAction.Purchase).getExecutableCriteria(session);
    //ecrit.setCacheable(true);

    List ls = ecrit.list();
    setPurchaseEntityList(ls);

    setProductList(null);
    ecrit = buildCriteriaForProduct().getExecutableCriteria(session);
    ls = ecrit.list();
    setProductList(ls);

    //        
    //        setEntityList(null);
    //        if (ls.size()>0){
    //           setEntityList(ls);
    //        }
    //      

    ecrit = buildCriteriaForPrice(TradeAction.Sale).getExecutableCriteria(session);
    ecrit.setCacheable(true);

    ls = ecrit.list();

    //        if (ls.size()>0){
    //           setEntityList(ls);
    //        }
    //        
    setSaleEntityList(ls);

    ecrit = buildCriteriaForWarehouse().getExecutableCriteria(session);
    ecrit.setCacheable(true);
    ecrit.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    warehouseResult = ecrit.list();
    calculateSummary();

    ecrit = buildCriteriaForPriceList(TradeAction.Sale).getExecutableCriteria(session);
    ls = ecrit.list();
    setSalePriceListResult(ls);

    ecrit = buildCriteriaForPriceList(TradeAction.Purchase).getExecutableCriteria(session);
    ls = ecrit.list();
    setPurchasePriceListResult(ls);

}

From source file:com.vmware.appfactory.application.dao.AppBuildRequestDaoImpl.java

License:Open Source License

/**
 * Get the list of buildRequests for a given app.
 *
 * @param appId//from ww w.j  a v  a  2  s  .  c o  m
 * @return
 */
@Override
@SuppressWarnings("unchecked")
public List<AppBuildRequest> findBuildRequestForApp(Long appId) {
    if (appId == null) {
        return Collections.EMPTY_LIST;
    }
    Criteria criteria = getCurrentSession().createCriteria(AppBuildRequest.class);
    criteria.add(Restrictions.eq("_application._id", appId));

    // Return distinct root entities.
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    return criteria.list();
}

From source file:com.vmware.appfactory.common.base.AbstractDaoImpl.java

License:Open Source License

/**
 * Helper method that simplifies data loopups based on a criterion.
 *
 * @param criterion//from   w  ww  . ja  v a2s . c o  m
 * @return
 */
@SuppressWarnings("unchecked")
protected List<T> findByCriterion(Criterion criterion) {
    Criteria criteria = getCurrentSession().createCriteria(_class);
    if (criterion != null) {
        criteria.add(criterion);
    }

    // Return distinct root entities. If not set, we can get duplicate rows.
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    return criteria.list();
}

From source file:com.vmware.appfactory.common.base.AbstractDaoImpl.java

License:Open Source License

/**
 * Returns the number of records matching the given criterion.
 *
 * @param criterion   condition to match
 * @return     a value from 0 to the number or rows in the table
 *///from   w w  w.  j  ava2s  .  co  m
protected long countByCriterion(Criterion criterion) {
    Criteria criteria = getCurrentSession().createCriteria(_class);
    if (criterion != null) {
        criteria.add(criterion);
    }

    // Return distinct root entities. If not set, we can get duplicate rows.
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    criteria.setProjection(Projections.rowCount());
    return (Long) criteria.uniqueResult();
}