JPAContainer giving incorrect results

I’m having a problem with JPAContainer giving incorrect results when querying a hierarchy.

The hierarchy in my DepartmentT entity is modeled in JPA as follows:

@NamedQuery(name = "DepartmentT.findAll", query = "SELECT d FROM DepartmentT d")
public class DepartmentT implements Serializable {
    private static final long serialVersionUID = 1L;

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int iddepartmentT;

    // bi-directional many-to-one association to DepartmentT: The Parent
    private DepartmentT departmentT;

    // bi-directional many-to-one association to DepartmentT: The Children
    @OneToMany(mappedBy = "departmentT", cascade = { CascadeType.ALL })
    private List<DepartmentT> departmentTs;

My JUnit test case is as follows:

initialize(); // clears the database through a stored procedure
createDepartments(); // builds the departments test set (non-hierarchical); stores to DB through JPAContainer
createHierarchy(); // adds the hierarchy to the department set by setting the parentId; stores to DB through JPAContainer
checkChildren(); // reloads from DB checks the hierarchy by looking at nodes' children

private void getChildren() {
DepartmentTDAO dao = new DepartmentTDAOImpl(); // <<=== JPAContainer instantiated here
BeanContainer<Integer, DepartmentT> departmentTs;

    departmentTs = dao.getAll();
    for (int x : departmentTs.getItemIds()) {
        DepartmentT d = departmentTs.getItem(x).getBean();

        int size = d.getChildren().size();  // <<=== ALWAYS 0

        if (d.getLevel() == 0)
            assertEquals(1, size);

        if (d.getLevel() == 1)
            assertEquals(1, size);

        if (d.getLevel() == 2)
            assertEquals(0, size);

[/code]Although the hierarchy is clearly correct in the DB, querying the children in this case always give size = 0. But, when I don’t initialize the DB at the beginning of the testcase, and just run the test with the data from the previous run, the size is returned correctly. What is messing up my test case? Can it be cache? I’m using EclipseLink.

So, turns out that switching off shared cache mode in persistence.xml did the trick. I don’t know what the side effects of that will be…