Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SuppressWarnings("unchecked")
- @Override
- public List<Company> getByQuery(String companyName) throws SQLException
- {
- Session s = null;
- CompanyDAOImpl company_dao = new CompanyDAOImpl();
- List<Company> result = new ArrayList<Company>();
- System.out.println("HELLLLO");
- try {
- s = session.openSession();
- s.beginTransaction();
- String criteria = " where ";
- if (companyName != null)
- criteria += " company.name like '%" + companyName + "%' ";
- else
- criteria += " true ";
- System.out.println(criteria);
- SQLQuery q = s.createSQLQuery("select distinct company.id, company.name from company" +
- criteria);
- System.out.println(q);
- List<Object[]> rows = q.list();
- for(Object[] row : rows)
- {
- int _id_ = (int) row[0];
- Company tmp = company_dao.getById(_id_);
- result.add(tmp);
- }
- s.getTransaction().commit();
- }
- finally
- {
- if (s != null && s.isOpen())
- s.close();
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement