Search in sources :

Example 1 with GasKey

use of org.hibernate.test.annotations.indexcoll.GasKey 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();
}
Also used : GasKey(org.hibernate.test.annotations.indexcoll.GasKey) Transaction(org.hibernate.Transaction) Gas(org.hibernate.test.annotations.indexcoll.Gas) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

Session (org.hibernate.Session)1 Transaction (org.hibernate.Transaction)1 Gas (org.hibernate.test.annotations.indexcoll.Gas)1 GasKey (org.hibernate.test.annotations.indexcoll.GasKey)1 Test (org.junit.Test)1