Example usage for org.hibernate Query setInteger

List of usage examples for org.hibernate Query setInteger

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setInteger(String name, int val) 

Source Link

Document

Bind a named int-valued parameter.

Usage

From source file:com.hibernate.dao.TelProvedorDAO.java

public Telefono buscaTelProvedor(int idTelefono) {
    Telefono telefono = null;/*from   ww w .  ja va  2s . c  o  m*/
    Transaction trns = null;
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        trns = session.beginTransaction();
        String queryString = "from Telefono where id = :id";
        Query query = session.createQuery(queryString);
        query.setInteger("id", idTelefono);
        telefono = (Telefono) query.uniqueResult();
    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
    return telefono;
}

From source file:com.hotel.management.dao.impl.BillDaoImpl.java

public void deleteById(int id) {
    Query query = getSession().createSQLQuery("delete from Bill where id = :id");
    query.setInteger("id", id);
    query.executeUpdate();//from  www.  j  a v a 2  s.c om
}

From source file:com.hotel.management.dao.impl.BookingDaoImpl.java

public void deleteById(int id) {
    Query query = getSession().createSQLQuery("delete from Booking where id = :id");
    query.setInteger("id", id);
    query.executeUpdate();/*from  w w  w.ja  va2  s  .  c o m*/
}

From source file:com.hotel.management.dao.impl.ClientDaoImpl.java

public void deleteById(int id) {
    Query query = getSession().createSQLQuery("delete from Client where id = :id");
    query.setInteger("id", id);
    query.executeUpdate();/* w w  w . j  av  a2s  .com*/
}

From source file:com.hotel.management.dao.impl.EmployeeDaoImpl.java

public void deleteById(int id) {
    Query query = getSession().createSQLQuery("delete from Employee where id = :id");
    query.setInteger("id", id);
    query.executeUpdate();/*from   ww  w  . java 2 s.com*/
}

From source file:com.hotel.management.dao.impl.ProfileDaoImpl.java

public void deleteById(int id) {
    Query query = getSession().createSQLQuery("delete from Profile where id = :id");
    query.setInteger("id", id);
    query.executeUpdate();// w  w  w .j a v  a 2 s . c  o m
}

From source file:com.hotel.management.dao.impl.RoleDaoImpl.java

public void deleteById(int id) {
    Query query = getSession().createSQLQuery("delete from Role where id = :id");
    query.setInteger("id", id);
    query.executeUpdate();/*from  www.  ja v a2s .  com*/
}

From source file:com.hotel.management.dao.impl.RoomDaoImpl.java

public void deleteById(int id) {
    Query query = getSession().createSQLQuery("delete from Room where id = :id");
    query.setInteger("id", id);
    query.executeUpdate();/*from   w  w w  .j ava  2  s. c om*/
}

From source file:com.hotel.management.dao.impl.RoomTypeDaoImpl.java

public void deleteById(int id) {
    Query query = getSession().createSQLQuery("delete from RoomType where id = :id");
    query.setInteger("id", id);
    query.executeUpdate();// w ww .  jav  a2s  .c  om
}

From source file:com.hp.j2sh.project.action.JoinCommunity.java

@Override
public String execute() throws Exception {
    try {/*from   w  w  w . jav a  2  s.  com*/
        Integer community_id = Integer.parseInt(communityId);
        Integer user = (Integer) sessionMap.get("user_id");
        System.out.println("Join :: " + community_id);
        System.out.println("user :: " + user);

        Session session = MyHibernateUtil.getSession();
        Transaction transaction = session.beginTransaction();

        CommunityUsers communityUsers = new CommunityUsers(community_id, (Integer) sessionMap.get("user_id"));

        session.save(communityUsers);
        transaction.commit();

        sessionMap.put("RegisterMessage", "Community successfully joined !!!");

        try {
            Query query = session.createQuery("FROM CommunityUsers c WHERE c.userId = :user");
            query.setInteger("user", user);
            System.out.println("query :: " + query.getQueryString());
            List<CommunityUsers> tempList = query.list();
            List<AllCommunities> listUser = new ArrayList<AllCommunities>();
            for (CommunityUsers communityUsers1 : tempList) {
                Criteria criteria2 = session.createCriteria(AllCommunities.class);
                criteria2.add(Restrictions.eq("communityId", communityUsers1.getCommunityId()));
                AllCommunities allCommunities1 = (AllCommunities) criteria2.list().iterator().next();
                listUser.add(allCommunities1);
            }
            sessionMap.put("communityListUser", listUser);

            List<AllCommunities> listAll = new ArrayList<AllCommunities>();
            List<Integer> userIds = new ArrayList<Integer>();
            for (AllCommunities allCommunities1 : listUser) {
                userIds.add(allCommunities1.getCommunityId());
            }
            System.out.println("userIDs :: " + userIds);
            Criteria criteria1 = session.createCriteria(AllCommunities.class);
            List<AllCommunities> tempListAll = criteria1.list();
            for (AllCommunities ac : tempListAll) {
                boolean found = false;
                for (Integer i : userIds) {
                    if (ac.getCommunityId().equals(i)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    listAll.add(ac);
                }
            }
            sessionMap.put("communityListAll", listAll);
        } catch (Exception e) {
            System.out.println("Join :: query :: " + e);
        }
        return SUCCESS;
    } finally {

    }
    //        catch (Exception e) {
    //            System.out.println("( JoinCommunity ) Exception :: " + e);
    //            sessionMap.put("RegisterMessage", "Community joining unsuccessful !!!");
    //            return ERROR;
    //        }
}