protected void clear() { UnitOfWork uow = acquireUnitOfWork(); // use alternate way for Symfoware as it doesn't support UpdateAll/DeleteAll on multi-table // objects (see rfe 298193) if (!(JUnitTestCase.getServerSession("fieldaccess")).getPlatform().isSymfoware()) { UpdateAllQuery updateEmployees = new UpdateAllQuery(Employee.class); updateEmployees.addUpdate("manager", null); updateEmployees.addUpdate("address", null); uow.executeQuery(updateEmployees); uow.executeQuery(new DeleteAllQuery(Employee.class)); } else { Iterator<Employee> emps = uow.readAllObjects(Employee.class).iterator(); while (emps.hasNext()) { Employee emp = emps.next(); emp.setManager(null); emp.setAddress(null); uow.deleteObject(emp); } ; } UpdateAllQuery updateProjects = new UpdateAllQuery(Project.class); updateProjects.addUpdate("teamLeader", null); uow.executeQuery(updateProjects); uow.executeQuery(new DeleteAllQuery(PhoneNumber.class)); uow.executeQuery(new DeleteAllQuery(Address.class)); uow.executeQuery(new DeleteAllQuery(Project.class)); uow.commit(); dbSessionClearCache(); }
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(); }