Example usage for org.hibernate Session createSQLQuery

List of usage examples for org.hibernate Session createSQLQuery

Introduction

In this page you can find the example usage for org.hibernate Session createSQLQuery.

Prototype

@Override
    NativeQuery createSQLQuery(String queryString);

Source Link

Usage

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

public static Object getFirstWithSql(String sql, Object param1, Object param2) throws HibernateException {
    Session session = getSession();
    SQLQuery query = session.createSQLQuery(sql);
    query.setParameter(0, param1);/* w w w .  j  a v  a2  s .  c o  m*/
    query.setParameter(01, param2);

    List<?> result = query.list();

    if (result == null || result.size() == 0) {
        return null;
    }

    return result.get(0);
}

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

@SuppressWarnings("unchecked")
public static <T> List<T> searchWithSql(Class<T> entityClass, String sql) throws HibernateException {
    Session session = getSession();

    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(entityClass);/*from ww  w.ja v  a 2 s.  co m*/
    List<T> result = query.list();

    return result;
}

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

@SuppressWarnings("unchecked")
public static <T> List<T> searchWithSql(Class<T> entityClass, String sql, Object param1)
        throws HibernateException {
    Session session = getSession();

    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(entityClass);//from  ww w .  ja v  a 2s.  c  om
    query.setParameter(0, param1);
    List<T> result = query.list();

    return result;
}

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

@SuppressWarnings("unchecked")
public static <T> List<T> searchWithSql(Class<T> entityClass, String sql, Object param1, Object param2)
        throws HibernateException {
    Session session = getSession();

    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(entityClass);//from   ww w .j a va  2 s.c  o  m
    query.setParameter(0, param1);
    query.setParameter(1, param2);
    List<T> result = query.list();

    return result;
}

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

@SuppressWarnings("unchecked")
public static <T> List<T> searchWithSql(Class<T> entityClass, String sql, Object param1, Object param2,
        Object param3) throws HibernateException {
    Session session = getSession();

    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(entityClass);//from  w w w.  ja v a2  s .c om
    query.setParameter(0, param1);
    query.setParameter(1, param2);
    query.setParameter(2, param3);
    List<T> result = query.list();

    return result;
}

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

@SuppressWarnings("unchecked")
public static <T> List<T> searchWithSql(Class<T> entityClass, String sql, Object param1, Object param2,
        Object param3, Object param4) throws HibernateException {
    Session session = getSession();

    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(entityClass);/*  ww  w  .jav  a 2s .  co m*/
    query.setParameter(0, param1);
    query.setParameter(1, param2);
    query.setParameter(2, param3);
    query.setParameter(3, param4);
    List<T> result = query.list();

    return result;
}

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

/**
 * Execute sql, return the result.//w  ww  .  j  av  a 2  s .  c om
 * 
 * @param sql
 * @param params
 * @return
 */
public static List<?> searchWithSql(String sql, Map<String, ?> params) throws HibernateException {
    Session session = getSession();
    SQLQuery query = session.createSQLQuery(sql);

    if (params != null) {
        Iterator<String> iterator = params.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            query.setParameter(key, params.get(key));
        }
    }

    List<?> result = query.list();

    return result;
}

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

/**
 * Execute sql, return the result./*from  w w w  . j  a  va2s  .c  om*/
 * 
 * @param sql
 * @param params
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> List<T> searchWithSql(String sql, Map<String, ?> params, Class<T> clazz)
        throws HibernateException {
    Session session = getSession();
    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(clazz);

    if (params != null) {
        Iterator<String> iterator = params.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            query.setParameter(key, params.get(key));
        }
    }

    List<T> result = query.list();

    return result;
}

From source file:com.globalsight.persistence.hibernate.HibernateUtil.java

License:Apache License

/**
 * Execute sql, return the result./* ww w  . ja  va2  s .  co m*/
 * 
 * @param sql
 * @param params
 * @return
 */
public static List<?> searchWithSqlWithIn(String sql, Map<String, ?> params, Map<String, List<Object>> ins)
        throws HibernateException {
    Session session = getSession();
    SQLQuery query = session.createSQLQuery(sql);

    if (params != null) {
        Iterator<String> iterator = params.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            query.setParameter(key, params.get(key));
        }
    }

    if (ins != null) {
        Iterator<String> iterator = ins.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            query.setParameterList(key, ins.get(key));
        }
    }

    List<?> result = query.list();

    return result;
}

From source file:com.grselectronics.inventario.controller.HibernateUtil.java

public List<Object> sendSQLQuery(String consulta) {
    List<Object> resultado = new ArrayList<>();
    Session sesion = sessionFactory.openSession();
    sesion.beginTransaction();//from  w  w  w .j  a v  a  2s. co  m
    resultado = sesion.createSQLQuery(consulta).list();
    sesion.getTransaction().commit();
    sesion.close();
    return resultado;
}