public void testOneToManyWithList() {
Account acc = new Account("acc1");
acc.setName(ACCOUNT_NAME);
acc.setUsers(5.0f);
mgr.fillInWithKey(acc);
Activity act1 = new Activity("act1");
act1.setAccount(acc);
act1.setName("dean");
act1.setNumTimes(3);
mgr.put(act1);
Activity act2 = new Activity("act2");
act2.setName("dean");
act2.setNumTimes(4);
mgr.put(act2);
acc.addActivity(act1);
acc.addActivity(act2);
mgr.put(acc);
mgr.flush();
Account accountResult = mgr.find(Account.class, acc.getId());
Assert.assertEquals(ACCOUNT_NAME, accountResult.getName());
Assert.assertEquals(acc.getUsers(), accountResult.getUsers());
List<Activity> activities = accountResult.getActivities();
Assert.assertEquals(2, activities.size());
//Now let's force proxy creation by getting one of the Activities
Activity activity = activities.get(0);
//This should NOT hit the database since the id is wrapped by the proxy and exists already
String id = activity.getId();
//since we added activity1 first, we better see that same activity be first in the list again...
Assert.assertEquals(act1.getId(), id);
//Now let's force a database lookup to have the activity filled in
Assert.assertEquals("dean", activity.getName());
}