List of usage examples for org.hibernate SQLQuery addEntity
SQLQuery<T> addEntity(Class entityType);
From source file:com.necl.core.daoImpl.TicketHeaderDaoImpl.java
@Override public List<TicketHeader> storedShowTicket(String ssoId) throws Exception { String sql = "EXEC PRO_ShowTickets :ssoId"; SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.setParameter("ssoId", ssoId); query.addEntity(TicketHeader.class); List results = query.list();//w w w . ja v a 2 s. c om return results; }
From source file:com.necl.core.daoImpl.TicketHeaderDaoImpl.java
@Override public List<TicketHeader> findByType(String type) throws Exception { String sql = "SELECT * FROM tblTicketsH " + "WHERE (TicketType = :ticketType) AND (TicketsFinished = :ticketFinished)" + "ORDER BY ApplicationDate DESC "; SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.addEntity(TicketHeader.class); query.setParameter("ticketType", type); query.setParameter("ticketFinished", "P"); List results = query.list();//from w ww .j a v a 2 s .co m return results; }
From source file:com.necl.core.daoImpl.TicketHeaderDaoImpl.java
@Override public List<TicketHeader> findByTypeArea(String type, String area) throws Exception { String sql = "SELECT *\n" + "FROM APP_USER INNER JOIN\n" + "tblMaster_Branch ON APP_USER.branchId = tblMaster_Branch.BranchID INNER JOIN\n" + "tblTicketsH ON APP_USER.SSO_ID = tblTicketsH.ApplicationName\n" + "WHERE (tblTicketsH.TicketType = :ticketType) AND (tblTicketsH.TicketsFinished = :ticketFinished) AND (tblMaster_Branch.Area = :area)\n" + "ORDER BY tblTicketsH.ApplicationDate DESC"; SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.addEntity(TicketHeader.class); query.setParameter("ticketType", type); query.setParameter("ticketFinished", "P"); query.setParameter("area", area); List results = query.list();/*from w w w . j ava 2 s . c om*/ return results; }
From source file:com.neu.web.phmis.dao.CommonDao.java
public UserBean activateAccount(UserBean userBean, String key) { try {/*from w ww. jav a 2 s. c om*/ session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); SQLQuery query = session.createSQLQuery("CALL activateAccount (:id, :password, :key, :ipAddr)"); query.setInteger("id", userBean.getId()); query.setString("password", userBean.getPassword()); query.setString("key", key); query.setString("ipAddr", userBean.getLastAccessedFrom()); List<UserBean> list = query.addEntity(UserBean.class).list(); if (!list.isEmpty()) { userBean = list.get(0); Hibernate.initialize(userBean.getEnterpriseBean()); Hibernate.initialize(userBean.getRoleBean()); } session.getTransaction().commit(); } catch (HibernateException e) { session.getTransaction().rollback(); userBean = null; e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); return userBean; } }
From source file:com.neu.web.phmis.dao.CommonDao.java
public UserBean authenticate(UserBean userBean, String ipAddr) { try {/*from w w w. j a v a2 s.co m*/ session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); SQLQuery query = session.createSQLQuery("CALL authenticateUser (:username, :password, :ipAddr)"); query.setString("username", userBean.getUsername()); query.setString("password", userBean.getPassword()); query.setString("ipAddr", ipAddr); List<UserBean> list = query.addEntity(UserBean.class).list(); if (!list.isEmpty()) { userBean = list.get(0); Hibernate.initialize(userBean.getEnterpriseBean()); Hibernate.initialize(userBean.getRoleBean()); } else { userBean = null; } session.getTransaction().commit(); } catch (HibernateException e) { session.getTransaction().rollback(); userBean = null; e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); return userBean; } }
From source file:com.neu.web.phmis.dao.InventoryDao.java
public void addOrder(List<OrderBean> orderList) { try {/*from w w w. j av a 2s .c o m*/ session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); for (OrderBean ob : orderList) { SQLQuery query = session.createSQLQuery("CALL addOrder(:1,:2,:3)"); query.setString("1", ob.getNumber()); query.setInteger("2", ob.getOrderedBy().getId()); query.setInteger("3", ob.getOrderedFrom().getId()); List<OrderItemBean> temp = ob.getOrderItemList(); ob = (OrderBean) query.addEntity(OrderBean.class).uniqueResult(); ob.setOrderItemList(temp); for (OrderItemBean oib : ob.getOrderItemList()) { query = session.createSQLQuery( "INSERT INTO orderitem (orderId, productId, quantity) VALUES (:1, :2, :3)"); query.setInteger("1", ob.getId()); query.setInteger("2", oib.getProductBean().getId()); query.setInteger("3", oib.getQuantity()); query.executeUpdate(); } } session.getTransaction().commit(); } catch (HibernateException e) { session.getTransaction().rollback(); e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); } }
From source file:com.ori.outlierserver.dao.ReadingsDao.java
public List<Reading> getLastNReadingsByClientId(String clientId, int N) { List<Reading> theReadingList = null; Session theSession = null;/* w ww . jav a 2s . co m*/ if (N <= 0) { return Collections.<Reading>emptyList(); } try { theSession = sessionFactory.openSession(); theSession.beginTransaction(); String sql = "SELECT * FROM readings WHERE client_id = :id limit :lim"; SQLQuery query = theSession.createSQLQuery(sql); query.addEntity(Reading.class); query.setString("id", clientId); query.setInteger("lim", N); theReadingList = query.list(); theSession.getTransaction().commit(); } catch (Exception e) { if (theSession != null) { theSession.getTransaction().rollback(); } } finally { if (theSession != null) { theSession.close(); } } return theReadingList; }
From source file:com.origen.hibernate.dao.general.DAOGeneral.java
public List<T> listarQueryNativo(String queryNativo) { Session session = this.sessionFactory.openSession(); SQLQuery query = session.createSQLQuery(queryNativo); query.addEntity(referenciaEntidad); List<T> results = (List<T>) query.list(); return results; }
From source file:com.school.dao.StageImplement.java
@Override public List<Stage> getAllStages() { List<Stage> stages = null; try {/*from w w w. j a v a 2 s . c o m*/ hibernateDriver.openSession(); String sql = "SELECT * FROM STAGE"; SQLQuery query = hibernateDriver.getSession().createSQLQuery(sql); query.addEntity(Stage.class); stages = query.list(); System.out.println("NUM OF STAGES:" + stages.size()); hibernateDriver.closeSession(); } catch (HibernateException ex) { ex.printStackTrace(); } return stages; }
From source file:com.school.dao.StageImplement.java
/** * ***************************************************************************************************** * **************************************** ROW OPERATION ******************************************************* * ***************************************************************************************************** * @param stage/*from w ww . j a v a 2 s . c o m*/ * @return */ @Override public List<RowsOFStage> getAllRows(Stage stage) { hibernateDriver.openSession(); String sql = "SELECT * FROM Rows_OF_Stage WHERE stage_id= :stageID"; SQLQuery query = hibernateDriver.getSession().createSQLQuery(sql); query.addEntity(RowsOFStage.class); query.setParameter("stageID", stage.getId()); List<RowsOFStage> results = query.list(); hibernateDriver.closeSession(); return results; }