Search in sources :

Example 1 with Rock

use of org.hibernate.test.annotations.inheritance.singletable.Rock in project hibernate-orm by hibernate.

the class SubclassTest method testFormula.

@Test
public void testFormula() throws Exception {
    Session s;
    Transaction tx;
    s = openSession();
    tx = s.beginTransaction();
    Rock guns = new Rock();
    guns.setAvgBeat(90);
    guns.setType(2);
    Noise white = new Noise();
    white.setAvgBeat(0);
    white.setType(null);
    s.persist(guns);
    s.persist(white);
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    List result = s.createCriteria(Noise.class).list();
    assertNotNull(result);
    assertEquals(1, result.size());
    white = (Noise) result.get(0);
    assertNull(white.getType());
    s.delete(white);
    result = s.createCriteria(Rock.class).list();
    assertEquals(1, result.size());
    s.delete(result.get(0));
    result = s.createCriteria(Funk.class).list();
    assertEquals(0, result.size());
    tx.commit();
    s.close();
}
Also used : Rock(org.hibernate.test.annotations.inheritance.singletable.Rock) Transaction(org.hibernate.Transaction) Noise(org.hibernate.test.annotations.inheritance.singletable.Noise) List(java.util.List) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

List (java.util.List)1 Session (org.hibernate.Session)1 Transaction (org.hibernate.Transaction)1 Noise (org.hibernate.test.annotations.inheritance.singletable.Noise)1 Rock (org.hibernate.test.annotations.inheritance.singletable.Rock)1 Test (org.junit.Test)1