Example usage for org.hibernate Session createNamedQuery

List of usage examples for org.hibernate Session createNamedQuery

Introduction

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

Prototype

<T> org.hibernate.query.Query<T> createNamedQuery(String name, Class<T> resultType);

Source Link

Usage

From source file:proy.datos.servicios.implementacion.FiltroHibernate.java

License:Mozilla Public License

public default ArrayList<T> listar(Session session) throws PersistenciaException {
    ArrayList<T> resultado = new ArrayList<>();
    try {/*from w  w w .j a v  a  2 s . c o m*/
        Query<T> query = null;
        if (!this.getNamedQueryName().isEmpty()) {
            query = session.createNamedQuery(this.getNamedQueryName(), getClase());
        } else {
            query = session.createQuery(this.getConsultaDinamica(), getClase());
        }
        this.setParametros(query);
        this.updateParametros(session);
        resultado = new ArrayList<>(query.list());
    } catch (Exception e) {
        throw new ConsultaException(e);
    }
    return resultado;
}