Example usage for org.hibernate SQLQuery addEntity

List of usage examples for org.hibernate SQLQuery addEntity

Introduction

In this page you can find the example usage for org.hibernate SQLQuery addEntity.

Prototype

SQLQuery<T> addEntity(Class entityType);

Source Link

Document

Declare a "root" entity, without specifying an alias.

Usage

From source file:ch.algotrader.dao.trade.OrderStatusDaoImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w  ww  . ja va 2 s  .co  m*/
public List<OrderStatus> findPending() {

    SQLQuery query = (SQLQuery) prepareQuery(null, "OrderStatus.findPending", QueryType.BY_NAME);
    query.addEntity(OrderStatusImpl.class);
    return query.list();
}

From source file:ch.astina.hesperid.dao.hibernate.AssetDAOHibernate.java

License:Apache License

@SuppressWarnings("unchecked")
public List<Asset> getAllRelatedAssets(Asset asset) {
    List<Asset> assets = new ArrayList<Asset>();

    String sql = "SELECT a.* FROM client_hierarchy ch INNER JOIN asset a ON a.id = ch.first_asset  WHERE first_asset = ?";
    SQLQuery query = session.createSQLQuery(sql);
    query.setLong(0, asset.getId());/* ww w.j  av a  2s .  co m*/
    query.addEntity(Asset.class);

    assets.addAll(query.list());

    sql = "SELECT a.* FROM client_hierarchy ch INNER JOIN asset a ON a.id = ch.first_asset  WHERE second_asset = ?";
    query = session.createSQLQuery(sql);
    query.setLong(0, asset.getId());
    query.addEntity(Asset.class);

    assets.addAll(query.list());

    return assets;
}

From source file:cn.trymore.core.dao.impl.DAOGenericImpl.java

License:Open Source License

@SuppressWarnings("rawtypes")
public List findListByNativeSQL(final String nativeSql, Class<?> claz) throws DAOException {
    SQLQuery query = getSession().createSQLQuery(nativeSql);
    // query.setCacheable(true);
    return query.addEntity(claz).list();
}

From source file:com.algoTrader.entity.marketData.TickDaoBase.java

/**
 * {@inheritDoc}//from   w ww .  j  a  va2 s.  com
 */
@Override
@SuppressWarnings("unchecked")
public Object findLastTickForSecurityAndMaxDate(final int transform, final String queryString,
        final int securityId, final Date maxDate) {
    try {
        SQLQuery queryObject = super.getSession(false).createSQLQuery(queryString);
        queryObject.addEntity(TickImpl.class);
        queryObject.setParameter("securityId", new Integer(securityId));
        queryObject.setParameter("maxDate", maxDate);
        Set results = new LinkedHashSet(queryObject.list());
        Object result = null;
        if (results.size() > 1) {
            throw new InvalidDataAccessResourceUsageException(
                    "More than one instance of 'com.algoTrader.entity.marketData.Tick"
                            + "' was found when executing query --> '" + queryString + "'");
        } else if (results.size() == 1) {
            result = results.iterator().next();
        }
        if (transform != TRANSFORM_NONE) {
            result = transformEntity(transform, (Tick) result);
        }
        return result;
    } catch (HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}

From source file:com.baomidou.hibernateplus.utils.HibernateUtils.java

License:Open Source License

/**
 * ?SQLQuery//from   ww w.  j  a v a  2  s  .  co  m
 *
 * @param sql
 * @param factory
 * @return
 */
public static Query getSqlQuery(Class<? extends Convert> cls, String sql, SessionFactory factory,
        Boolean isCurrent) {
    System.err.println("Execute SQL" + SqlUtils.sqlFormat(sql, true));
    SQLQuery sqlQuery = getSession(factory, isCurrent).createSQLQuery(sql);
    if (cls != null) {
        sqlQuery.addEntity(cls);
    }
    return sqlQuery;
}

From source file:com.bitranger.parknshop.buyer.dao.CustomerFavouriteItemDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<CustomerFavouriteItem> findByCustomerId(final Integer psCustomerId, final FetchOption option) {
    try {//from   ww w .  j  a  v a 2  s .co m
        return getHibernateTemplate().executeFind(new HibernateCallback<List<CustomerFavouriteItem>>() {

            @Override
            public List<CustomerFavouriteItem> doInHibernate(Session session)
                    throws HibernateException, SQLException {

                SQLQuery query = session
                        .createSQLQuery("select * from customer_favourite_item as C where C.id_customer = ?"
                                + " order by C.time_created "
                                + (option.sortOption == SortOption.ASCENDING ? "asc" : "desc")
                                + " limit ? offset ?");
                query.setInteger(0, psCustomerId);
                query.setInteger(1, option.limit);
                query.setInteger(2, option.offset);
                query.addEntity(CustomerFavouriteItem.class);
                return query.list();
            }
        });
    } catch (RuntimeException e) {
        log.error("get failed", e);
        throw e;
    }
}

From source file:com.bitranger.parknshop.buyer.dao.impl.CartCustomerItemDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   ww w . java 2  s.c  o m*/
public List<CartCustomerItem> findByCustomerId(final Integer psCustomerId, final FetchOption option) {

    log.debug("getting CartCustomerItem instance with psCustomerId: " + psCustomerId);
    try {
        return getHibernateTemplate().executeFind(new HibernateCallback<List<CartCustomerItem>>() {

            @Override
            public List<CartCustomerItem> doInHibernate(Session session)
                    throws HibernateException, SQLException {

                SQLQuery query = session
                        .createSQLQuery("select * from cart_customer_item as C where C.id_customer = ?"
                                + " order by C.time_created "
                                + (option.sortOption == SortOption.ASCENDING ? "asc" : "desc")
                                + " limit ? offset ?");
                query.setInteger(0, psCustomerId);
                query.setInteger(1, option.limit);
                query.setInteger(2, option.offset);
                query.addEntity(CartCustomerItem.class);
                return query.list();
            }
        });
    } catch (RuntimeException e) {
        log.error("get failed", e);
        throw e;
    }
}

From source file:com.bitranger.parknshop.buyer.dao.PsNoticeCustomerDAO.java

License:Open Source License

@SuppressWarnings("unchecked")

public List<PsNoticeCustomer> getLatest(final int customerID, final int n) {

    return getHibernateTemplate().executeFind(new HibernateCallback<List<PsNoticeCustomer>>() {

        @Override//w w  w.  j av  a  2 s. c o  m
        public List<PsNoticeCustomer> doInHibernate(Session arg0) throws HibernateException, SQLException {

            SQLQuery q = arg0.createSQLQuery(" select ps_notice_customer as NC "
                    + " where NC.is_valid = 1 and id_customer = ? " + " order by time_created desc limit ?");
            q.setInteger(0, customerID);
            q.setInteger(1, n);
            q.addEntity(PsNoticeCustomer.class);
            return q.list();
        }

    });
}

From source file:com.bitranger.parknshop.common.ads.PsPromotItemDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<PsPromotItem> findBySeller(final int id) {
    return getHibernateTemplate().executeFind(new HibernateCallback<List<PsPromotItem>>() {

        @Override//  w w w  . jav  a 2 s  .co m
        public List<PsPromotItem> doInHibernate(Session session) throws HibernateException, SQLException {
            SQLQuery q = session.createSQLQuery(" select IP.* from ps_promot_item as IP "
                    + " inner join ps_item as IT on IT.id = IP.id_item "
                    + " inner join ps_shop as SP on SP.id = IT.id_shop " + " where SP.id_seller = ? ");
            q.setInteger(0, id);
            q.addEntity(PsPromotItem.class);
            return q.list();
        }
    });
}

From source file:com.bitranger.parknshop.common.ads.PsPromotItemDAO.java

License:Open Source License

/**
 select PI.* from ps_promot_item as PI //from  w  ww  .j a v a  2s.com
   inner join ps_ad_item as AD on AD.id_promot = PI.id
where AD.time_start < CURRENT_TIMESTAMP and CURRENT_TIMESTAMP < AD.time_end
        
 */
@SuppressWarnings("unchecked")
public List<PsPromotItem> findAllValid() {
    log.debug("finding all PsPromotItem instances");
    try {
        return getHibernateTemplate().executeFind(new HibernateCallback<List<PsPromotItem>>() {

            @Override
            public List<PsPromotItem> doInHibernate(Session session) throws HibernateException, SQLException {
                SQLQuery q = session.createSQLQuery("      select PI.* from ps_promot_item as PI "
                        + "   inner join ps_ad_item as AD on AD.id_promot = PI.id "
                        + "   where AD.time_start < CURRENT_TIMESTAMP and CURRENT_TIMESTAMP < AD.time_end ");
                q.addEntity(PsPromotItem.class);
                return q.list();
            }
        });
    } catch (RuntimeException re) {
        log.error("find all failed", re);
        throw re;
    }
}