Search in sources :

Example 76 with Transaction

use of org.hibernate.Transaction in project hibernate-orm by hibernate.

the class IdTest method testIdInEmbeddableSuperclass.

@Test
public void testIdInEmbeddableSuperclass() throws Exception {
    Session s;
    Transaction tx;
    s = openSession();
    tx = s.beginTransaction();
    FirTree chrismasTree = new FirTree();
    s.persist(chrismasTree);
    tx.commit();
    s.clear();
    tx = s.beginTransaction();
    chrismasTree = (FirTree) s.get(FirTree.class, chrismasTree.getId());
    assertNotNull(chrismasTree);
    s.delete(chrismasTree);
    tx.commit();
    s.close();
}
Also used : FirTree(org.hibernate.test.annotations.id.sequences.entities.FirTree) Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Example 77 with Transaction

use of org.hibernate.Transaction in project hibernate-orm by hibernate.

the class IdTest method testParameterizedAuto.

@Test
public void testParameterizedAuto() throws Exception {
    Session s;
    Transaction tx;
    s = openSession();
    tx = s.beginTransaction();
    Home h = new Home();
    s.persist(h);
    tx.commit();
    s.close();
    assertNotNull(h.getId());
    s = openSession();
    tx = s.beginTransaction();
    Home reloadedHome = (Home) s.get(Home.class, h.getId());
    assertEquals(h.getId(), reloadedHome.getId());
    s.delete(reloadedHome);
    tx.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Home(org.hibernate.test.annotations.id.sequences.entities.Home) Session(org.hibernate.Session) Test(org.junit.Test)

Example 78 with Transaction

use of org.hibernate.Transaction in project hibernate-orm by hibernate.

the class IdTest method testGenericGenerator.

@Test
public void testGenericGenerator() throws Exception {
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    SoundSystem system = new SoundSystem();
    system.setBrand("Genelec");
    system.setModel("T234");
    Furniture fur = new Furniture();
    s.persist(system);
    s.persist(fur);
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    system = (SoundSystem) s.get(SoundSystem.class, system.getId());
    fur = (Furniture) s.get(Furniture.class, fur.getId());
    assertNotNull(system);
    assertNotNull(fur);
    s.delete(system);
    s.delete(fur);
    tx.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) SoundSystem(org.hibernate.test.annotations.id.sequences.entities.SoundSystem) Furniture(org.hibernate.test.annotations.id.sequences.entities.Furniture) Session(org.hibernate.Session) Test(org.junit.Test)

Example 79 with Transaction

use of org.hibernate.Transaction in project hibernate-orm by hibernate.

the class IdTest method testMethodLevelGenerator.

@Test
public void testMethodLevelGenerator() throws Exception {
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    Department b = new Department();
    s.persist(b);
    tx.commit();
    s.close();
    assertNotNull(b.getId());
    s = openSession();
    tx = s.beginTransaction();
    s.delete(s.get(Department.class, b.getId()));
    tx.commit();
    s.close();
}
Also used : Department(org.hibernate.test.annotations.id.sequences.entities.Department) Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Example 80 with Transaction

use of org.hibernate.Transaction in project hibernate-orm by hibernate.

the class IdTest method testClassLevelGenerator.

@Test
public void testClassLevelGenerator() throws Exception {
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    Store b = new Store();
    s.persist(b);
    tx.commit();
    s.close();
    assertNotNull(b.getId());
    s = openSession();
    tx = s.beginTransaction();
    s.delete(s.get(Store.class, b.getId()));
    tx.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Store(org.hibernate.test.annotations.id.sequences.entities.Store) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

Transaction (org.hibernate.Transaction)1273 Session (org.hibernate.Session)1251 Test (org.junit.Test)1124 List (java.util.List)239 ArrayList (java.util.ArrayList)143 Iterator (java.util.Iterator)87 TestForIssue (org.hibernate.testing.TestForIssue)87 Query (org.hibernate.Query)80 BigDecimal (java.math.BigDecimal)73 Date (java.util.Date)52 HashSet (java.util.HashSet)44 Criteria (org.hibernate.Criteria)39 SkipForDialect (org.hibernate.testing.SkipForDialect)36 ScrollableResults (org.hibernate.ScrollableResults)35 Set (java.util.Set)30 PersistenceException (javax.persistence.PersistenceException)30 HashMap (java.util.HashMap)29 Map (java.util.Map)25 FailureExpected (org.hibernate.testing.FailureExpected)23 Serializable (java.io.Serializable)22