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:dao.CourseHibernateDao.java

@Override
public Course findCourseByNameAndGroupName(String courseName, MyGroup group) {
    Query query = getSession().createQuery("from Course where name = :name AND myGroup = :group");
    query.setString("name", courseName);
    query.setEntity("group", group);
    query.setMaxResults(1);/* ww  w  . j  a  va  2  s .  co m*/
    return (Course) query.uniqueResult();
}

From source file:dao.CourseHibernateDao.java

@Override
public List<Course> findCoursesByGroup(MyGroup group) {
    Query query = getSession().createQuery("from Course where myGroup= :group");
    query.setEntity("group", group);
    return query.list();
}

From source file:dao.FacultyDAO.java

@Override
public List<Customer> getFacultyCustomer(Faculty faculty) {
    List<Customer> obj;/*w w  w .  jav  a 2  s .  c  o m*/
    Session sess = sessionFactory.openSession();
    Transaction tx = sess.getTransaction();
    try {
        //set transaction timeout to 3 seconds
        tx.setTimeout(3);
        tx.begin();
        Query query = sess.createQuery("FROM Customer where advisor = :fa");
        query.setEntity("fa", faculty);
        obj = query.list();
        tx.commit();
    } catch (Exception e) {
        tx.rollback();
        throw e; // or display error message
    } finally {
        sess.close();
    }
    return obj;
}

From source file:dao.FacultyDAO.java

@Override
public List<Section> getSections(Faculty faculty) {
    List<Section> obj;/*from www. j  a  va  2s . com*/
    Session sess = sessionFactory.openSession();
    Transaction tx = sess.getTransaction();
    try {
        //set transaction timeout to 3 seconds
        tx.setTimeout(3);
        tx.begin();
        Query query = sess.createQuery("FROM Section where faculty =:fa");
        query.setEntity("fa", faculty);
        obj = query.list();
        tx.commit();
    } catch (Exception e) {
        tx.rollback();
        throw e; // or display error message
    } finally {
        sess.close();
    }
    return obj;
}

From source file:dao.LabHibernateDao.java

@Override
public Lab findLabByNameAndCourseName(String labName, Course course) {
    Query query = getSession().createQuery("from Lab where name = :name AND course = :course");
    query.setString("name", labName);
    query.setEntity("course", course);
    query.setMaxResults(1);//ww  w .  j  av  a 2s.com
    return (Lab) query.uniqueResult();
}

From source file:dao.LabHibernateDao.java

@Override
public List<Lab> findlabsByCoursesByGroup(Course course) {
    Query query = getSession().createQuery("from Lab where course= :course");
    query.setEntity("course", course);
    return query.list();
}

From source file:dao.RegionDao.java

public Region getRegion(Long regId, User user) {
    String hql = "from Region where id=:regId and user=:user";
    Query query = getCurrentSession().createQuery(hql);
    query.setEntity("user", user);
    query.setParameter("regId", regId);
    return (Region) query.uniqueResult();
}

From source file:dao.RodadaDao.java

public List<Rodada> listarRodadasAbertasPorCompeticao(Competicao competicao) {
    try {/*from w w w.j av  a  2  s  . c o  m*/
        if (competicao == null) {
            return null;
        }

        Session sessao = Hibernate4Util.getSessionFactory();
        Transaction transacao = sessao.beginTransaction();
        Query consulta = sessao.createQuery("SELECT ro " + " FROM Rodada ro" + " JOIN ro.competicao c"
                + " WHERE c = ?" + " AND (fechada IS NULL) OR (fechada = false)");
        consulta.setEntity(0, competicao);
        List<Rodada> resultado = consulta.list();
        transacao.commit();
        return resultado;
    } catch (HibernateException e) {
        System.out.println("No foi possvel selecionar as rodadas. Erro: " + e.getMessage());
        throw new HibernateException(e);
    }
}

From source file:dao.TimeCompeticaoDao.java

public TimeCompeticao buscarRegistro(Time time, Competicao competicao) {
    try {/*www. j  a v  a 2 s.c  o m*/
        Session sessao = Hibernate4Util.getSessionFactory();
        Transaction transacao = sessao.beginTransaction();
        Query consulta = sessao
                .createQuery("SELECT tc " + " FROM TimeCompeticao tc" + " INNER JOIN tc.time AS tm"
                        + " INNER JOIN tc.competicao AS cm" + " WHERE (tm = ?) AND (cm = ?)");
        consulta.setEntity(0, time);
        consulta.setEntity(1, competicao);

        TimeCompeticao resultado = (TimeCompeticao) consulta.uniqueResult();
        transacao.commit();
        return resultado;
    } catch (HibernateException e) {
        System.out.println(
                "No foi possvel buscar o vinculo de time por competio. Erro: " + e.getMessage());
    }

    return null;
}

From source file:dao.TimeCompeticaoDao.java

public List<TimeCompeticao> listarPorCompeticao(Competicao competicao) {
    try {//w ww  . j a v  a2s.  c o m
        Session sessao = Hibernate4Util.getSessionFactory();
        Transaction transacao = sessao.beginTransaction();
        Query consulta = sessao.createQuery("SELECT tc " + " FROM TimeCompeticao tc"
                + " INNER JOIN tc.competicao AS cm" + " WHERE (cm = ?)");
        consulta.setEntity(0, competicao);
        List<TimeCompeticao> resultado = consulta.list();
        transacao.commit();
        return resultado;
    } catch (HibernateException e) {
        System.out.println(
                "No foi possvel selecionar o vinculo de time por competio. Erro: " + e.getMessage());
        throw new HibernateException(e);
    }
}