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:com.ant.myteam.dao.RecordDao.java

private RatingRecord checkExistRatingRecord(RatingRecord ratingRecord) {
    Query query = sessionFactory.getCurrentSession().createQuery(
            "FROM RatingRecord RR WHERE RR.record.recordId = :recordId AND RR.user.userId = :userId");
    query.setParameter("recordId", ratingRecord.getRecord().getRecordId());
    query.setParameter("userId", ratingRecord.getUser().getUserId());
    return (RatingRecord) query.uniqueResult();
}

From source file:com.ant.myteam.dao.UserDao.java

public User checkUserExisted(User user) {
    try {//  w  ww .  j  a va 2  s  . c om
        Query query;
        if (user.getPassword() == null || user.getPassword().equals("")) {
            query = sessionFactory.getCurrentSession().createQuery("FROM User WHERE username = :username");
            query.setParameter("username", user.getUserName());
        } else {
            query = sessionFactory.getCurrentSession()
                    .createQuery("FROM User WHERE username = :username AND password = :password");
            query.setParameter("username", user.getUserName());
            query.setParameter("password", user.getPassword());
        }

        //if( query.uniqueResult() != null )
        return (User) query.uniqueResult();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.ant.myteam.dao.UserDao.java

public UserGCM checkUserGCMExisted(Long userId) {
    Query query = sessionFactory.getCurrentSession().createQuery("FROM UserGCM WHERE userId = :userId");
    query.setParameter("userId", userId);
    return (UserGCM) query.uniqueResult();
}

From source file:com.app.caja.SobranteFaltanteCaja.java

private ArqueoCab obtenerHabilitacion(int oper) {
    ArqueoCab arq = null;/*w  w  w . j  a v  a2  s . c  o  m*/

    try {
        //arq = (ArqueoCab) st.get(ArqueoCab.class, oper);
        if (origen.equals("Nuevo")) {
            Query query = st.createQuery("From ArqueoCab a Where a.nroOperacion = ? and a.estado = 'A'");
            query.setParameter(0, oper);

            arq = (ArqueoCab) query.uniqueResult();

        } else {
            arq = (ArqueoCab) st.get(ArqueoCab.class, oper);
        }
        if (arq == null && origen.equals("Nuevo")) {
            JOptionPane.showMessageDialog(null, "El arqueo no existe o ya fue cerrado.",
                    "Sobrante / Faltante de Caja", JOptionPane.INFORMATION_MESSAGE);
        }

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Ocurrio un error al realizar consulta. " + "\n" + e.getMessage(),
                "Error - Sobrante / Faltante de Caja", JOptionPane.ERROR_MESSAGE);
    }
    return arq;
}

From source file:com.app.gpo.dao.FieldDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public Field findByfieldOriginID(String fieldOriginID) {
    Query query = getSession().createQuery("from Field as f where f.fieldOriginID = :fieldOriginID)");
    query.setString("fieldOriginID", fieldOriginID);
    return (Field) query.uniqueResult();
}

From source file:com.app.gpo.dao.OrderItemDAO.java

License:Open Source License

public OrderItem findByOrderNumber(String orderNumber) {
    Query query = getSession().createSQLQuery("select from orderItem where orderNumber = :orderNumber");
    query.setString("orderNumber", orderNumber);
    OrderItem orderItem = (OrderItem) query.uniqueResult();
    Hibernate.initialize(orderItem.getorderItemFields());
    return orderItem;
}

From source file:com.app.gpo.dao.OrderStatusDAO.java

License:Open Source License

public OrderStatus findByName(String statusName) {
    Query query = getSession()
            .createQuery("from OrderStatus as oS where oS.orderStatusName = :orderStatusName)");
    query.setString("orderStatusName", statusName);
    return (OrderStatus) query.uniqueResult();
}

From source file:com.app.gpo.dao.OrderStatusDAO.java

License:Open Source License

public OrderStatus findIdByName(String statusName) {
    Query query = getSession()
            .createQuery("from OrderStatus as oS where oS.orderStatusName = :orderStatusName)");
    query.setString("orderStatusName", statusName);
    OrderStatus orderStatus = (OrderStatus) query.uniqueResult();
    return orderStatus;
}

From source file:com.app.mantenimiento.Bancos.java

public String obtnerId() {
    int cantidad = 0;
    try {/*from ww  w.j  a va 2s .  c  o m*/
        Query query = st.createQuery("select max(c.codBanco) from MtBancos c");
        cantidad = (int) query.uniqueResult();
    } catch (NullPointerException ex) {
        cantidad = 0;
    } catch (HibernateException ex) {
        JOptionPane.showMessageDialog(null, "Ocurrio un error al obtener valor del ID. " + ex.getMessage(),
                "Mantenimiento de Cargos", JOptionPane.ERROR_MESSAGE);
    }
    return String.valueOf(cantidad + 1);
}

From source file:com.app.mantenimiento.Cargos.java

public String obtnerId() {
    int cantidad = 0;
    try {/* ww w  .j  a  v a2  s  .co  m*/
        Query query = st.createQuery("select max(c.codCargo) from MtCargos c");
        cantidad = (int) query.uniqueResult();
    } catch (HibernateException ex) {
        JOptionPane.showMessageDialog(null, "Ocurrio un error al obtener valor del ID. " + ex.getMessage(),
                "Mantenimiento de Cargos", JOptionPane.ERROR_MESSAGE);
    }
    return String.valueOf(cantidad + 1);
}