writer.delete(department3);
    public void testStoreObjectWithReferencedObject() throws Exception {        Department department2 = null;        Department department3 = null;        try {            writer.store(address1);            writer.store(company1);            writer.store(department1);            writer.store(employee1);            // Check that the department is referenced            Object returned = writer.getObjectByExample(employeeTemplate);            assertEquals(employee1, returned);            assertEquals(department1, ((Employee) returned).getDepartment());            department2 = new Department();            department2.setName("Department 2");            department2.setCompany(company1);            writer.store(department2);            // Override the department            employee1.setDepartment(department2);            writer.store(employee1);            // Check that the new department is referenced            returned = writer.getObjectByExample(employeeTemplate);            assertEquals(employee1, returned);            assertEquals(department2, ((Employee) returned).getDepartment());            // Set department to null            employee1.setDepartment(null);            writer.store(employee1);            // Check that the department is not referenced            returned = writer.getObjectByExample(employeeTemplate);            assertEquals(employee1, returned);            assertEquals(null, ((Employee) returned).getDepartment());            // Store a reference to department that is not yet in the database            department3 = new Department();            department3.setName("Department 3 (not in db)");            department3.setCompany(company1);            employee1.setDepartment(department3);            writer.store(employee1);            // Now store department3            writer.store(department3);            // Check that the department3 is referenced, even though it was not            // previously in database            returned = writer.getObjectByExample(employeeTemplate);            assertEquals(employee1, returned);            assertEquals(department3, ((Employee) returned).getDepartment());        } finally {            writer.delete(employee1);            writer.delete(department1);            writer.delete(department2);            writer.delete(company1);            writer.delete(address1);        }    }