Example usage for org.hibernate Query uniqueResult

List of usage examples for org.hibernate Query uniqueResult

Introduction

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

Prototype

R uniqueResult();

Source Link

Document

Convenience method to return a single instance that matches the query, or null if the query returns no results.

Usage

From source file:br.com.droganet.dao.FuncionarioDAO.java

public Funcionario consultar(String nome) {
    conexao.beginTransaction();//from w  w w  .  ja va 2s .c  om
    Query query = conexao.createQuery("from funcionario where nome = " + nome);
    Funcionario j = (Funcionario) query.uniqueResult();
    conexao.getTransaction().commit();
    return j;
}

From source file:br.com.droganet.dao.ItemDAO.java

public Item consultar(String nome) {
    conexao.beginTransaction();/* w  w  w .  jav  a2s .  c  om*/
    Query query = conexao.createQuery("from item where nome = " + nome);
    Item j = (Item) query.uniqueResult();
    conexao.getTransaction().commit();
    return j;
}

From source file:br.com.droganet.dao.LojaDAO.java

public Loja consultar(String nome) {
    conexao.beginTransaction();//from ww  w  .  j a  v  a2  s  .co m
    Query query = conexao.createQuery("from loja where nome = " + nome);
    Loja j = (Loja) query.uniqueResult();
    conexao.getTransaction().commit();
    return j;
}

From source file:br.com.droganet.dao.MedicamentoDAO.java

public Medicamento consultar(String nome) {
    conexao.beginTransaction();//www.j  av a  2  s . c o m
    Query query = conexao.createQuery("from medicamento where nome = " + nome);
    Medicamento j = (Medicamento) query.uniqueResult();
    conexao.getTransaction().commit();
    return j;
}

From source file:br.com.droganet.dao.PlanoDAO.java

public Plano consultar(int id) {
    conexao.beginTransaction();//www .j av  a2s . c  om
    Query query = conexao.createQuery("from Plano where idPlano = " + id);
    Plano j = (Plano) query.uniqueResult();
    conexao.getTransaction().commit();
    return j;
}

From source file:br.com.droganet.dao.TipoDAO.java

public Tipo consultar(String nome) {
    conexao.beginTransaction();//from w  ww.ja v a  2  s.c  o m
    Query query = conexao.createQuery("from tipo where nome = " + nome);
    Tipo j = (Tipo) query.uniqueResult();
    conexao.getTransaction().commit();
    return j;
}

From source file:br.com.fatec.modelo.DAORepositorio.java

public T procurarPorUsuarioESenha(String login, String senha) {
    Query query = null;
    T result = null;/*from  ww  w. j ava 2s .c  o  m*/
    try {
        query = session.createQuery("from Usuario where login = :login and senha = :senha");
        query.setParameter("login", login);
        query.setParameter("senha", senha);
        result = (T) query.uniqueResult();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        session.disconnect();
        session.close();
    }

    return result;
}

From source file:br.com.fatecmogidascruzes.saph.dao.UserDAO.java

@Override
public User getUserByCredentials(Credential credential) {

    session = HSession.getSession();/*w  ww .  j a va 2  s  .  com*/
    String hql = "from User usr WHERE :login = usr.credential.login AND :password = usr.credential.password";
    Query q = session.createQuery(hql);
    q.setString("login", credential.getLogin());
    q.setString("password", credential.getPassword());
    User user = (User) q.uniqueResult();

    return user;
}

From source file:br.com.financeiro.dao.UsuarioDAOHibernate.java

@Override
public Usuario buscaPorLogin(String login) {
    String hql = "select u from Usuario u where u.login = :login";
    Query consulta = this.session.createQuery(hql);
    consulta.setString("login", login);
    return (Usuario) consulta.uniqueResult();
}

From source file:br.com.gvt.eng.vod.dao.AssetDAO.java

public List<OnDemandContentVO> findTop50() {

    StringBuilder aux = new StringBuilder(
            "select a.assetId, count(*) as total from IpvodPurchase p join p.ipvodAsset a group by a.assetId order by total desc");

    Query query = getSession().createQuery(String.valueOf(aux));
    query.setFirstResult(0);//from   www  . ja v  a 2  s.c om
    query.setMaxResults(50);

    @SuppressWarnings("unchecked")
    List<Object[]> list = query.list();

    List<OnDemandContentVO> vos = new ArrayList<OnDemandContentVO>();

    for (Object[] obj : list) {

        StringBuilder hql = new StringBuilder("select ");
        hql.append("a.title as title, ");
        hql.append("a.originalTitle as originalTitle, ");
        hql.append("'UNKNOWN' as genre, ");
        hql.append("c.description as category, ");
        hql.append("a.subtitles as subtitle, ");
        hql.append("a.country as country, ");
        hql.append("sc.description as subCategory, ");
        hql.append("a.assetId as assetId, ");
        hql.append("a.creationDate as creationDate, ");
        hql.append("a.description as description, ");
        hql.append("a.director as director, ");
        hql.append("a.actors as actors, ");
        hql.append("a.episode as episode, ");
        hql.append("a.billingID as billingID, ");
        hql.append("a.episodeName as episodeName, ");
        hql.append("a.licenseWindowEnd as licenseWindowEnd, ");
        hql.append("a.licenseWindowStart as licenseWindowStart, ");
        hql.append("a.price as price, ");
        hql.append("a.releaseYear as releaseYear, ");
        hql.append("a.season as season, ");
        hql.append("a.languages as languages, ");
        hql.append("a.assetInfo as assetInfo, ");
        hql.append("r.rating as rating, ");
        hql.append("r.adult as isAdult, ");
        hql.append("a.totalTime as totalTime, ");
        hql.append("a.product as product, ");
        hql.append("a.screenFormat as screenFormat, ");
        hql.append("a.audioType as audioType, ");
        hql.append("a.canResume as canResume, ");
        hql.append("a.isHD as isHD, ");
        hql.append("a.isRevised as isRevised, ");
        hql.append("a.fileSize as fileSize, ");
        hql.append("a.checksum as checksum, ");
        hql.append("a.bitrate as bitrate, ");
        hql.append("a.titleAlternative as titleAlternative, ");
        hql.append("at.description as assetType, ");
        hql.append("cp.providerId as contentProvider ");
        hql.append(
                "from IpvodAsset as a left join a.ipvodCategory1 c left join a.ipvodCategory2 sc left join a.ipvodAssetType at left join a.ipvodContentProvider cp left join a.rating r ");
        hql.append("where a.assetId = :assetId order by a.title asc ");

        query = getSession().createQuery(String.valueOf(hql));
        query.setParameter("assetId", obj[0]);
        query.setResultTransformer(new AliasToBeanResultTransformer(OnDemandContentVO.class));

        OnDemandContentVO vo = (OnDemandContentVO) query.uniqueResult();
        vo.setOrder(new Long(list.lastIndexOf(obj) + 1));

        vos.add(list.lastIndexOf(obj), vo);

    }

    return vos;
}