public class BusinessService{ public static SessionFactory sessionFactory; static{ try{ Configuration config = new Configuration(); config.addClass(Company.class) .addClass(HourlyEmployee.class) .addClass(SalariedEmployee.class); sessionFactory = config.buildSessionFactory(); }catch(Exception e){e.PRintStackTrace();} }
public void saveEmployee(Employee employee) throws Exception{……} public List findAllEmployees() throws Exception{……} public Company loadCompany(long id) throws Exception{……}
public void test() throws Exception{ List employees=findAllEmployees(); printAllEmployees(employees.iterator());
Company company=loadCompany(1); printAllEmployees(company.getEmployees().iterator());
List results=new ArrayList(); tx = session.beginTransaction(); List hourlyEmployees=session.find("from HourlyEmployee"); results.addAll(hourlyEmployees);
List salariedEmployees=session.find("from SalariedEmployee"); results.addAll(salariedEmployees);