@Test
public void test002()
{
EntityManagerFactory emf = null;
EntityManager
em = null;
emf =
javax.persistence.Persistence.createEntityManagerFactory("testpu");
em =
emf.createEntityManager();
em.getTransaction().begin();
em.createNativeQuery("DELETE FROM ECLENTA_ENTB").executeUpdate();
em.createNativeQuery("DELETE FROM ECL295EntA").executeUpdate();
em.createNativeQuery("DELETE FROM ECL295EntB").executeUpdate();
em.getTransaction().commit();
em.close();
em =
emf.createEntityManager();
em.getTransaction().begin();
final int entBCount
= 10;
ECL295EntB[]
entBArr = new
ECL295EntB[entBCount];
for (int i = 0; i
< entBCount; i++) {
ECL295EntB
entB = new
ECL295EntB();
entB.setId(i+1);
entB.setStrData("Entity
B-" + i);
em.persist(entB);
entBArr[i]
= entB;
}
SecureRandom
sr = new
SecureRandom();
for (int i = 0; i
< 10; i++) {
ECL295EntA
entA = new
ECL295EntA();
entA.setId(i+1);
entA.setStrData("EntA-"
+ i);
StringBuffer sb = new StringBuffer();
for (int j = 0; j
< 200; j++) {
sb.append(sr.nextLong());sb.append(' ');
}
entA.setStringValue(sb.toString());
for (int j = 0; j
< entBCount; j++) {
entBArr[j].getEntACollection().put(entA.getStrData(),
entA);
}
em.persist(entA);
}
em.getTransaction().commit();
em.close();
emf.close();
emf =
javax.persistence.Persistence.createEntityManagerFactory("testpu");
em =
emf.createEntityManager();
Query q =
em.createQuery("SELECT
b from ECL295EntB b");
q.setHint(QueryHints.BATCH , "b.entACollection");
List<ECL295EntB> resultSet = q.getResultList();
assertNotNull(resultSet);
ECL295EntB
entB_find = resultSet.get(0); //
em.find(ECL295EntB.class, 1);
assertNotNull(entB_find);
boolean
containsTarget =
entB_find.getEntACollection().containsKey("EntA-1");
assertTrue(containsTarget);
assertEquals(10,
entB_find.getEntACollection().size());
}
...