Example usage for org.hibernate Query setEntity

List of usage examples for org.hibernate Query setEntity

Introduction

In this page you can find the example usage for org.hibernate Query setEntity.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
Query<R> setEntity(String name, Object val);

Source Link

Document

Bind an instance of a mapped persistent class to a named query parameter.

Usage

From source file:br.ifes.gerenciadormesada.dao.GastoDAO.java

public List<Gasto> buscaPorMesada(Mesada mesada) {
    MesadaEntidade mesadaEntidade;/* w  w w  . j  a v  a  2  s.c  o m*/
    MesadaConverte mesadaConverte = new MesadaConverte();
    Query consulta;
    List<GastoEntidade> entidades;
    List<Gasto> gastos = new ArrayList<Gasto>();

    String hql = "select u from GastoEntidade u where u.mesada = :mesada ";

    this.iniciaOperacao();

    consulta = this.sessao.createQuery(hql);

    mesadaEntidade = mesadaConverte.ModeloParaEntidade(mesada);

    consulta.setEntity("mesada", mesadaEntidade);

    entidades = (List<GastoEntidade>) consulta.list();

    if (entidades != null) {
        Gasto gasto;

        for (GastoEntidade entidade : entidades) {
            gasto = this.conversor.EntidadeParaModelo(entidade);

            gastos.add(gasto);
        }

        return gastos;
    }

    return null;
}

From source file:br.ifes.gerenciadormesada.dao.MesadaDAO.java

public Mesada buscaPorMesAnoBeneficiado(Beneficiado beneficiado, int mes, int ano) {
    BeneficiadoEntidade beneficiadoEntidade;
    BeneficiadoConverte beneficiadoConverte = new BeneficiadoConverte();
    MesadaEntidade entidade;/*from   w  ww .  j av a2s . co  m*/
    Query consulta;
    // TODO Auto-generated method stub
    String hql = "select u from MesadaEntidade u where u.beneficiado = :beneficiado and u.mes = :mes and u.ano =:ano ";

    this.iniciaOperacao();

    consulta = this.sessao.createQuery(hql);

    beneficiadoEntidade = beneficiadoConverte.ModeloParaEntidade(beneficiado);

    consulta.setEntity("beneficiado", beneficiadoEntidade);
    consulta.setInteger("mes", mes);
    consulta.setInteger("ano", ano);

    entidade = (MesadaEntidade) consulta.uniqueResult();

    if (entidade != null) {
        return this.conversor.EntidadeParaModelo(entidade);
    }

    return null;
}

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

License:Apache License

@SuppressWarnings("unchecked")
@Override//from   ww  w.jav  a 2  s.  c o  m
public List<Observer> getClientObservers(Asset asset) {
    Query query = session.createQuery("from Observer o " + "where o.observerStrategy.observationScope = :scope "
            + "and o.asset = :asset order by o.name");
    query.setParameter("scope", ObservationScope.CLIENT);
    query.setEntity("asset", asset);
    return query.list();
}

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

License:Apache License

@SuppressWarnings("unchecked")
@Override//from  www.  j a  v  a 2  s .  c  om
public List<Observer> getExternalObservers(Asset asset) {
    Query query = session.createQuery("from Observer o " + "where o.observerStrategy.observationScope = :scope "
            + "and o.asset = :asset order by o.name");
    query.setParameter("scope", ObservationScope.EXTERNAL);
    query.setEntity("asset", asset);
    return query.list();
}

From source file:com.appeligo.alerts.PendingAlert.java

License:Apache License

public static void markDeletedForProgramAlert(ProgramAlert programAlert) {
    Permissions.checkUser(programAlert.getUser());
    Session session = getSession();/*from www . j a va2  s .c  om*/
    Query query = session.getNamedQuery("PendingAlert.markDeletedForProgramAlert");
    query.setEntity("programAlert", programAlert);
    query.executeUpdate();
}

From source file:com.appeligo.alerts.ProgramAlert.java

License:Apache License

public static void markDeletedForProgram(User user, String programId) {
    Permissions.checkUser(user);/*from   w w w.jav a 2s  .  c o  m*/
    Session session = getSession();
    Query query = session.getNamedQuery("ProgramAlert.markDeletedForProgram");
    query.setEntity("user", user);
    query.setString("programId", programId);
    query.executeUpdate();
}

From source file:com.appeligo.alerts.ProgramAlert.java

License:Apache License

@SuppressWarnings("unchecked")
public static List<ProgramAlert> getByProgramId(User user, String programId) {
    Permissions.checkUser(user);//  ww  w  . j a v a2  s  . c om
    Session session = getSession();
    Query query = session.getNamedQuery("ProgramAlert.getByProgramIdForUser");
    query.setEntity("user", user);
    query.setString("programId", programId);
    List<ProgramAlert> programAlerts = query.list();
    return programAlerts;
}

From source file:com.appeligo.search.entity.Favorite.java

License:Apache License

public static Favorite getTopFavoriteShow(User user) {
    Permissions.checkUser(user);/*from  ww w.ja v a2  s .  c om*/
    Session session = getSession();
    Query query = session.getNamedQuery("Favorite.getFavoriteNonEpisodes");
    query.setMaxResults(1);
    query.setEntity("user", user);
    return (Favorite) query.uniqueResult();
}

From source file:com.appeligo.search.entity.Favorite.java

License:Apache License

public static Favorite getTopFavoriteEpisode(User user) {
    Permissions.checkUser(user);//from www. j  av a2  s . c  om
    Session session = getSession();
    Query query = session.getNamedQuery("Favorite.getFavoriteEpisodes");
    query.setMaxResults(1);
    query.setEntity("user", user);
    return (Favorite) query.uniqueResult();
}

From source file:com.appeligo.search.entity.Favorite.java

License:Apache License

public static List<Favorite> getFavoriteShows(User user) {
    Permissions.checkUser(user);//from  ww  w. jav  a  2 s.  com
    Session session = getSession();
    Query query = session.getNamedQuery("Favorite.getFavoriteNonEpisodes");
    query.setEntity("user", user);
    return query.list();
}