Search in sources :

Example 1 with PlanetCheatSheet

use of org.hibernate.test.annotations.id.sequences.entities.PlanetCheatSheet in project hibernate-orm by hibernate.

the class EnumIdTest method testEnumAsId.

@Test
public void testEnumAsId() throws Exception {
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    PlanetCheatSheet mercury = new PlanetCheatSheet();
    mercury.setPlanet(Planet.MERCURY);
    mercury.setMass(3.303e+23);
    mercury.setRadius(2.4397e6);
    mercury.setNumberOfInhabitants(0);
    s.persist(mercury);
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    PlanetCheatSheet mercuryFromDb = (PlanetCheatSheet) s.get(PlanetCheatSheet.class, mercury.getPlanet());
    assertNotNull(mercuryFromDb);
    log.debug(mercuryFromDb.toString());
    s.delete(mercuryFromDb);
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    mercury = (PlanetCheatSheet) s.get(PlanetCheatSheet.class, Planet.MERCURY);
    assertNull(mercury);
    tx.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) PlanetCheatSheet(org.hibernate.test.annotations.id.sequences.entities.PlanetCheatSheet) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

Session (org.hibernate.Session)1 Transaction (org.hibernate.Transaction)1 PlanetCheatSheet (org.hibernate.test.annotations.id.sequences.entities.PlanetCheatSheet)1 Test (org.junit.Test)1