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:agh.musicapplication.mappdao.MUserRepository.java

@Override
public MUser findUserByLogin(String login) {
    Query query = getSession().createQuery("from MUser where login = :login");
    query.setParameter("login", login);
    return (MUser) query.uniqueResult();
}

From source file:agh.musicapplication.mappdao.MUserReviewRepository.java

@Override
public Long getCountOfMUserReview(MUser user) {
    Query query = getSession().createQuery("select count(*) from MUserReview m where m.user=:user");
    query.setParameter("user", user);
    Long count = (Long) query.uniqueResult();
    return count;
}

From source file:agh.musicapplication.mappdao.MUserVocalistRepository.java

@Override
public Long getCountOfMUserVocalist(MUser user) {
    Query query = getSession().createQuery("select count(*) from MUserVocalist m where m.user=:user");
    query.setParameter("user", user);
    Long count = (Long) query.uniqueResult();
    return count;
}

From source file:agh.musicapplication.mappdao.MUserVocalistRepository.java

@Override
public Double getAvgVocalistRankOfSomeUser(MUser user) {
    Query query = getSession().createQuery("select avg(m.grade) from MUserVocalist m where m.user=:user");
    query.setParameter("user", user);
    Double average = (Double) query.uniqueResult();
    return average;
}

From source file:agh.musicapplication.mappdao.MVocalistRepository.java

@Override
public MVocalist findVocalistByName(String vocalistArtisticName) {
    Query query = getSession().createQuery("from MVocalist where artisticName = :vocalistArtisticName");
    query.setParameter("vocalistArtisticName", vocalistArtisticName);
    return (MVocalist) query.uniqueResult();
}

From source file:aish.vaishno.hibernatesample.FoodOrderDao.java

public FoodOrder getParticularFoodOrder(Long id) {
    //Session session = HibernateUtil.getHibernateUtil;
    Query query = session.createQuery("from FoodOrder where id= :id").setParameter("id", id);
    return (FoodOrder) query.uniqueResult();
}

From source file:angeldx.manager.EstudianteManager.java

public Estudiante buscarPorId(int id) {
    Estudiante est = null;// www  .  j  av  a2  s. co  m
    Transaction tran = null;
    Session session = HibernateUtil.openSession();
    try {
        tran = session.beginTransaction();
        String queryString = "from Estudiante where id = :id";
        Query query = session.createQuery(queryString);
        query.setInteger("id", id);
        est = (Estudiante) query.uniqueResult();
    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
    return est;
}

From source file:app.HdHelper.java

public Hoadon getHDByID(int HdId) {
    Hoadon hoadon = null;/*from w  w  w. ja  v a 2s. com*/
    try {
        org.hibernate.Transaction tx = session.beginTransaction();
        Query q = session.createQuery("from Hoadon as hoadon where hoadon.maHd=" + HdId);
        hoadon = (Hoadon) q.uniqueResult();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return hoadon;
}

From source file:app.KhHelper.java

public Khachhang getUserByID(int userId) {
    Khachhang khachhang = null;//from www.j  a  va2  s .c o m
    try {
        org.hibernate.Transaction tx = session.beginTransaction();
        Query q = session.createQuery("from Khachhang as khachhnag where khachhang.maKh=" + userId);
        khachhang = (Khachhang) q.uniqueResult();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return khachhang;
}

From source file:app.persistencia.DAO.java

/**
 * Esta funcion nos devuelve el valor mximo del campo ID de la base de
 * datos/*from w ww  . ja v a  2 s .co  m*/
 *
 * @param entidad String que se refiere al nombre de la clase de la que
 * queremos obtener el ID. No confundir con el nombre de la tabla de la base
 * de datos a la que persistimos.
 *
 * @return ID - integer
 */
public int getID(String entidad) {
    cerrarConexion();
    abrirConexion();
    int max = -1;
    System.out.println("MAX: " + max);
    try {

        Query q1 = session.createQuery("select max(id) from " + entidad);
        q1.setMaxResults(1);
        max = (int) q1.uniqueResult();
        max = max + 1;
        System.out.println("MAX: " + max);

    } catch (HibernateException e) {
        System.out.println(
                "Error al consultar la ID de la entidad " + entidad + " . Mas detalles -->" + e.getMessage());
    }

    return max;

}