I’ve switched to using Oracle for the database, and still cannot reproduce with ECL 2.5.0. Switching to use a ReadAllQuery did not change the outcome, either (attempt left commented out.)
...
[EL Fine]: sql: 2014-09-04 10:01:33.078--ServerSession(544214961)--Connection(1725418407)--CREATE TABLE ECL295ENTA (ID NUMBER(10) NOT NULL, STRDATA VARCHAR2(255) NULL, STRINGVALUE CLOB NULL, PRIMARY KEY (ID))
[EL Fine]: sql: 2014-09-04 10:01:33.148--ServerSession(544214961)--Connection(1725418407)--CREATE TABLE ECL295ENTB (ID NUMBER(10) NOT NULL, STRDATA VARCHAR2(255) NULL, PRIMARY KEY (ID))
[EL Fine]: sql: 2014-09-04 10:01:33.213--ServerSession(544214961)--Connection(1725418407)--CREATE TABLE ECLENTA_ENTB (ECL295EntB_ID NUMBER(10) NOT NULL, entACollection_ID NUMBER(10) NOT NULL, PRIMARY KEY (ECL295EntB_ID, entACollection_ID))
[EL Fine]: sql: 2014-09-04 10:01:33.28--ServerSession(544214961)--Connection(1725418407)--ALTER TABLE ECLENTA_ENTB ADD CONSTRAINT ECLENTA_ENTB_entACollection_ID FOREIGN KEY (entACollection_ID) REFERENCES ECL295ENTA (ID)
[EL Fine]: sql: 2014-09-04 10:01:33.348--ServerSession(544214961)--Connection(1725418407)--ALTER TABLE ECLENTA_ENTB ADD CONSTRAINT FK_ECLENTA_ENTB_ECL295EntB_ID FOREIGN KEY (ECL295EntB_ID) REFERENCES ECL295ENTB (ID)
@Test
public void test002() {
EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("testpu");
populateDB(emf);
EntityManager em = emf.createEntityManager();
// ReadAllQuery raQuery = new ReadAllQuery(ECL295EntB.class);
// raQuery.setJPQLString("SELECT OBJECT(b) FROM ECL295EntB b");
// List resultSet = (List) ((org.eclipse.persistence.internal.jpa.EntityManagerImpl) em).getSession().executeQuery(raQuery);
Query q = em.createQuery("SELECT OBJECT(b) from ECL295EntB b");
q.setHint(QueryHints.BATCH , "b.entACollection");
q.setHint(QueryHints.QUERY_TYPE, QueryType.ReadObject);
List<ECL295EntB> resultSet = q.getResultList();
assertNotNull(resultSet);
ECL295EntB entB_find = (ECL295EntB) 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());
}
private void populateDB(EntityManagerFactory emf) {
System.out.println("Populating DB...");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.createNativeQuery("DELETE FROM ECLENTA_ENTB").executeUpdate();
em.createNativeQuery("DELETE FROM ECLENTA_ENTB2").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];
SecureRandom sr = new SecureRandom();
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;
}
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();
System.out.println("DB population complete.");
}
}