List of usage examples for org.hibernate SQLQuery addEntity
SQLQuery<T> addEntity(Class entityType);
From source file:com.itrus.ca.common.persistence.BaseDaoImpl.java
License:Open Source License
private void setResultTransformer(SQLQuery query, Class[] resultClass) { if (resultClass == null || resultClass.length <= 0) return;/*from w ww . j a v a 2 s. co m*/ for (Class cls : resultClass) { query.addEntity(cls); } }
From source file:com.jredrain.dao.HibernateDao.java
License:Apache License
/** * Query//from w w w . j ava2s . c o m * * @param query * @param beanClass * @return */ private SQLQuery setQueryType(SQLQuery query, Class beanClass) { if (getClassMetadata(beanClass) != null) { query.addEntity(beanClass); } else { query.setResultTransformer(BeanResultTransFormer.get(beanClass)); } return query; }
From source file:com.liyablieva.jaxws.dao.EmployeeDAOImpl.java
@SuppressWarnings("unchecked") @Override//from w ww .j a v a 2 s .c om @Transactional(value = "transactionManager") public List<Employee> getEmployees(String department) { System.out.println("In get employees DAO"); int departmentId = getDepartmentId(department); System.out.println("Department = " + department + ", departmentId = " + departmentId); List<Employee> employees = Collections.emptyList(); String sql = "SELECT * FROM employee WHERE department_id = :department_id"; SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.addEntity(Employee.class); query.setParameter("department_id", departmentId); employees = query.list(); return employees; }
From source file:com.mpos.controller.ControllerSelect.java
public static String getISO(String country) { String ISO = ""; Session session = factory.openSession(); Transaction tx = null;/*from www . jav a 2s .c o m*/ try { tx = session.beginTransaction(); String sql = "SELECT * FROM abbreviation WHERE Country = '" + country + "'"; SQLQuery query = session.createSQLQuery(sql); query.addEntity(ModelAbbrevilation.class); List location = query.list(); if (location.isEmpty()) { ISO = "NULL"; } else { for (Iterator iterator = location.iterator(); iterator.hasNext();) { ModelAbbrevilation place = (ModelAbbrevilation) iterator.next(); ISO = place.getISO(); } } tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); } e.printStackTrace(); } return ISO; }
From source file:com.mpos.controller.ControllerSelect.java
public static ArrayList<String> selector(String country) { ArrayList<String> data = new ArrayList<>(); String ISO = getISO(country); Session session = factory.openSession(); Transaction tx = null;/*from w w w . j a v a 2 s . c o m*/ try { tx = session.beginTransaction(); String sql = "SELECT * FROM location WHERE ISO = '" + ISO + "'"; SQLQuery query = session.createSQLQuery(sql); query.addEntity(ModelLocation.class); List location = query.list(); if (location.isEmpty()) { data.add("NULL"); } else { for (Iterator iterator = location.iterator(); iterator.hasNext();) { ModelLocation place = (ModelLocation) iterator.next(); data.add(place.getName()); data.add(String.valueOf(place.getLat())); data.add(String.valueOf(place.getLng())); data.add(String.valueOf(place.getISO())); data.add(String.valueOf(place.getProvince())); } } tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); // = clear transection ? } e.printStackTrace(); } finally { session.close(); // CLOSE CONNECTION //factory.close(); } return data; }
From source file:com.mx.teknei.pcabordo.lib.dao.impl.SbctAlarDAO.java
@Override public SbctAlar getAlarForName(String nameAlar) { SbctAlar s_alar = null;/*from w w w.j a v a 2 s . c o m*/ Transaction trans = null; Session session = null; try { session = LoadConnection.getSessionFactory().openSession(); } catch (ExceptionInInitializerError eiie) { System.out.println("Error al iniciar la coneccion a BD postgres:" + eiie.getMessage()); } catch (Exception e) { System.err.println("Error en LoadConnection." + e.getMessage()); } try { trans = session.beginTransaction(); SQLQuery query = session.createSQLQuery("select * from sitm.sbct_alar s where s.des_alar=?"); query.addEntity(SbctAlar.class); query.setString(0, nameAlar); s_alar = (SbctAlar) query.uniqueResult(); } catch (Exception e) { e.printStackTrace(); } finally { session.flush(); session.close(); } return s_alar; //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
From source file:com.mx.teknei.pcabordo.lib.dao.impl.SfalConfDAO.java
@Override public SfalConf getAlarConfForName(String nameConfAlar) { SfalConf s_alar = null;/*w ww . j a va2s . c o m*/ Transaction trans = null; Session session = null; try { session = LoadConnection.getSessionFactory().openSession(); } catch (ExceptionInInitializerError eiie) { System.out.println("Error al iniciar la coneccion a BD postgres:" + eiie.getMessage()); } catch (Exception e) { System.err.println("Error en LoadConnection." + e.getMessage()); } try { trans = session.beginTransaction(); SQLQuery query = session.createSQLQuery( "SELECT * FROM sitm.sfal_conf s WHERE s.id_alar = (SELECT id_alar from sitm.sbct_alar where des_alar = ? )"); query.addEntity(SfalConf.class); query.setString(0, nameConfAlar); s_alar = (SfalConf) query.uniqueResult(); } catch (Exception e) { e.printStackTrace(); } finally { session.flush(); session.close(); } return s_alar; }
From source file:com.necl.core.daoImpl.SectionDaoImpl.java
@Override public Section findById(String division, String section) throws Exception { logger.info("division : " + division + " Section : " + section); String sql = "SELECT DivisionCode, SectionCode, SectionName, SectionBudget, SectionActual " + "FROM tblMaster_Section " + "WHERE (SectionCode = :section) AND (DivisionCode = :division)"; SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.addEntity(Section.class); query.setParameter("section", section); query.setParameter("division", division); List results = query.list();// ww w .j a v a 2 s. c o m return (Section) results.get(0); }
From source file:com.necl.core.daoImpl.TicketDetailDaoImpl.java
@Override public boolean delete(int id) throws Exception { String sql = "DELETE FROM tblTicketsD WHERE id = :id"; SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.addEntity(TicketDetail.class); query.setParameter("id", id); query.executeUpdate();/* w ww.ja v a2 s .c om*/ return true; }
From source file:com.necl.core.daoImpl.TicketHeaderDaoImpl.java
@Override public List<TicketHeader> storedShowApproves(User user) throws Exception { String sql = "EXEC PRO_ShowApproves :positionCode , :divisionCode , :userName"; SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.setParameter("positionCode", user.getPositionCode()); query.setParameter("divisionCode", user.getDivisionCode()); query.setParameter("userName", user.getSsoId()); query.addEntity(TicketHeader.class); List results = query.list();/*w w w .j a v a2s .c o m*/ return results; }