use of org.hibernate.test.annotations.indexcoll.Gas in project hibernate-orm by hibernate.
the class EagerIndexedCollectionTest method testEntityKeyElementTarget.
@Test
public void testEntityKeyElementTarget() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Atmosphere atm = new Atmosphere();
Gas o2 = new Gas();
o2.name = "oxygen";
atm.composition.put(o2, 94.3);
s.persist(o2);
s.persist(atm);
s.flush();
s.clear();
atm = (Atmosphere) s.get(Atmosphere.class, atm.id);
assertTrue(Hibernate.isInitialized(atm.composition));
assertEquals(1, atm.composition.size());
assertEquals(o2.name, atm.composition.keySet().iterator().next().name);
tx.rollback();
s.close();
}
use of org.hibernate.test.annotations.indexcoll.Gas in project hibernate-orm by hibernate.
the class EagerIndexedCollectionTest method testRealMap.
@Test
public void testRealMap() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Atmosphere atm = new Atmosphere();
Atmosphere atm2 = new Atmosphere();
GasKey key = new GasKey();
key.setName("O2");
Gas o2 = new Gas();
o2.name = "oxygen";
atm.gases.put("100%", o2);
atm.gasesPerKey.put(key, o2);
atm2.gases.put("100%", o2);
atm2.gasesPerKey.put(key, o2);
s.persist(key);
s.persist(atm);
s.persist(atm2);
s.flush();
s.clear();
atm = (Atmosphere) s.get(Atmosphere.class, atm.id);
key = (GasKey) s.get(GasKey.class, key.getName());
assertEquals(1, atm.gases.size());
assertEquals(o2.name, atm.gases.get("100%").name);
assertEquals(o2.name, atm.gasesPerKey.get(key).name);
tx.rollback();
s.close();
}
Aggregations