Hi Andrew, thanks for your reply. Following your suggestions:
- Used PersistenceUnitUtil in my integration test, but to no avail
- @RooEntity is definitely set in my real code
- Made Set private like my other fields
- Changed Set from TreeSet to HashSet
I still was not getting the Set populated in my integration test, so I enabled SQL debugging as you suggested. This shed some light on things, since I was not seeing the SELECT statement when calling the Roo-generated Mother.findMother(long id) method to fetch the Mother object that I had previously persisted in the test. This has led me to believe that some caching mechanism is in effect with EclipseLink, so I disabled caching for my entity as follows:
Code:
@Cache (
type=CacheType.WEAK,
isolation=CacheIsolationType.SHARED,
expiry=60000,
alwaysRefresh=true,
disableHits=true,
coordinationType=CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS
)
public class Mother { ... }
I have also added the following option to persistence.xml:
Code:
<property name="eclipselink.query-results-cache" value="false"/>
So, either I still am not configuring my EclipseLink cache correctly, or there is some other reason why Mother.findMother(long id) is not returning the set of children in the returned Mother object. Here is the code from my integration test:
Code:
Mother mom = new Mother();
mom.persist();
mom.flush()
// mom is correctly inserted
Assert.assertNotNull("mom id should not be null", mom.getId());
Baby child = new Baby();
child.setMother(mom);
// child is correctly inserted, referencing mom
child = child.merge();
Assert.assertNotNull("child id should not be null", child.getId());
Mother freshMom = Mother.findMother(mom.getId());
Assert.assertNotNull("freshMom should not be null", freshMom);
Assert.assertEquals(mom, freshMom); // this passes... I would think it should not
Assert.assertTrue("freshMom should have at least one child", freshMom.getBabies().size() > 0); // this fails, I would expect it to pass since I just added it
Is there still an issue my caching, or is there another reason why the Mother.babies Set is not being populated?
Thanks.