{ final Employee employee1 = new Employee(); employee1.setStaffNo(1234); employee1.setFirstname("Lucy"); employee1.setLastname("Smith"); employee1.setSex("w"); employee1.setDepartment("research"); this.employees.put(employee1.getStaffNo(), employee1); final Employee employee2 = new Employee(); employee2.setStaffNo(3210); employee2.setFirstname("Jack"); employee2.setLastname("Jonson"); employee2.setSex("m"); employee2.setDepartment("purchase"); this.employees.put(employee2.getStaffNo(), employee2); }
public static void main(String[] args) { SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession(); session.beginTransaction(); Department department = new Department(); department.setDepartmentName("Sales"); session.save(department); Employee emp1 = new Employee("Nina", "Mayers", "1212"); Employee emp2 = new Employee("Tony", "Almeida", "4343"); emp1.setDepartment(department); emp2.setDepartment(department); session.save(emp1); session.save(emp2); session.getTransaction().commit(); session.close(); }
private void prepareTestData(Session s) { Employee john = new Employee("John Doe"); john.setCompany("JBoss"); john.setDepartment("hr"); john.setTitle("hr guru"); john.setRegion("US"); Employee polli = new Employee("Polli Wog"); polli.setCompany("JBoss"); polli.setDepartment("hr"); polli.setTitle("hr novice"); polli.setRegion("US"); polli.setManager(john); john.getMinions().add(polli); Employee suzie = new Employee("Suzie Q"); suzie.setCompany("JBoss"); suzie.setDepartment("hr"); suzie.setTitle("hr novice"); suzie.setRegion("EMEA"); suzie.setManager(john); john.getMinions().add(suzie); Customer cust = new Customer("John Q Public"); cust.setCompany("Acme"); cust.setRegion("US"); cust.setContactOwner(john); Person ups = new Person("UPS guy"); ups.setCompany("UPS"); ups.setRegion("US"); s.save(john); s.save(cust); s.save(ups); s.flush(); }
void testModifyEmployee() { Department department1 = this.new Department(); Department department2 = this.new Department(); Employee employee1 = new Employee(); Employee employee2 = new Employee(); AssociationTests.assertCollection(department1.getEmployees()); AssociationTests.assertCollection(department2.getEmployees()); Assert.assertNull(employee1.getDepartment()); Assert.assertNull(employee2.getDepartment()); employee1.setDepartment(department1); AssociationTests.assertCollection(department1.getEmployees(), employee1); AssociationTests.assertCollection(department2.getEmployees()); Assert.assertEquals(department1, employee1.getDepartment()); Assert.assertNull(employee2.getDepartment()); employee2.setDepartment(department1); AssociationTests.assertCollection(department1.getEmployees(), employee1, employee2); AssociationTests.assertCollection(department2.getEmployees()); Assert.assertEquals(department1, employee1.getDepartment()); Assert.assertEquals(department1, employee2.getDepartment()); employee1.setDepartment(department2); AssociationTests.assertCollection(department1.getEmployees(), employee2); AssociationTests.assertCollection(department2.getEmployees(), employee1); Assert.assertEquals(department2, employee1.getDepartment()); Assert.assertEquals(department1, employee2.getDepartment()); employee2.setDepartment(department2); AssociationTests.assertCollection(department1.getEmployees()); AssociationTests.assertCollection(department2.getEmployees(), employee1, employee2); Assert.assertEquals(department2, employee1.getDepartment()); Assert.assertEquals(department2, employee2.getDepartment()); employee2.setDepartment(null); AssociationTests.assertCollection(department1.getEmployees()); AssociationTests.assertCollection(department2.getEmployees(), employee1); Assert.assertEquals(department2, employee1.getDepartment()); Assert.assertNull(employee2.getDepartment()); employee1.setDepartment(null); AssociationTests.assertCollection(department1.getEmployees()); AssociationTests.assertCollection(department2.getEmployees()); Assert.assertNull(employee1.getDepartment()); Assert.assertNull(employee2.getDepartment()); }