Search in sources :

Example 36 with Transaction

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

the class AccessTest method testFieldsOverriding.

@Test
public void testFieldsOverriding() throws Exception {
    Gardenshed gs = new Gardenshed();
    gs.floors = 4;
    Session s = openSession();
    s.persist(gs);
    Transaction tx = s.beginTransaction();
    tx.commit();
    s.clear();
    tx = s.beginTransaction();
    gs = (Gardenshed) s.get(Gardenshed.class, gs.getId());
    assertEquals(4, gs.floors);
    assertEquals(6, gs.getFloors());
    s.delete(gs);
    tx.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Example 37 with Transaction

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

the class AccessTest method testSuperclassNonOverriding.

@Test
public void testSuperclassNonOverriding() throws Exception {
    Furniture fur = new Furniture();
    fur.setGod("Buddha");
    Session s = openSession();
    s.persist(fur);
    Transaction tx = s.beginTransaction();
    tx.commit();
    s.clear();
    tx = s.beginTransaction();
    fur = (Furniture) s.get(Furniture.class, fur.getId());
    assertNotNull(fur.getGod());
    s.delete(fur);
    tx.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Example 38 with Transaction

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

the class AccessTest method testNonOverridenSubclass.

@Test
public void testNonOverridenSubclass() throws Exception {
    Chair chair = new Chair();
    chair.setPillow("Blue");
    Session s = openSession();
    s.persist(chair);
    Transaction tx = s.beginTransaction();
    tx.commit();
    s.clear();
    tx = s.beginTransaction();
    chair = (Chair) s.get(Chair.class, chair.getId());
    assertNull(chair.getPillow());
    s.delete(chair);
    tx.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Example 39 with Transaction

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

the class AccessTest method testDefaultConfigurationModeIsInherited.

@Test
public void testDefaultConfigurationModeIsInherited() throws Exception {
    User john = new User();
    john.setFirstname("John");
    john.setLastname("Doe");
    List<User> friends = new ArrayList<User>();
    User friend = new User();
    friend.setFirstname("Jane");
    friend.setLastname("Doe");
    friends.add(friend);
    john.setFriends(friends);
    Session s = openSession();
    s.persist(john);
    Transaction tx = s.beginTransaction();
    tx.commit();
    s.clear();
    tx = s.beginTransaction();
    john = (User) s.get(User.class, john.getId());
    assertEquals("Wrong number of friends", 1, john.getFriends().size());
    assertNull(john.firstname);
    s.delete(john);
    tx.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) ArrayList(java.util.ArrayList) Session(org.hibernate.Session) Test(org.junit.Test)

Example 40 with Transaction

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

the class CompositeIdTest method testManyToOneInCompositePk.

/**
	 * This feature is not supported by the EJB3
	 * this is an hibernate extension
	 */
@Test
public void testManyToOneInCompositePk() throws Exception {
    Session s;
    Transaction tx;
    s = openSession();
    tx = s.beginTransaction();
    ParentPk ppk = new ParentPk();
    ppk.setFirstName("Emmanuel");
    ppk.setLastName("Bernard");
    Parent p = new Parent();
    p.id = ppk;
    s.persist(p);
    ChildPk cpk = new ChildPk();
    cpk.parent = p;
    cpk.nthChild = 1;
    Child c = new Child();
    c.id = cpk;
    s.persist(c);
    tx.commit();
    s.close();
    s = openSession();
    tx = s.beginTransaction();
    Query q = s.createQuery("select c from Child c where c.id.nthChild = :nth");
    q.setInteger("nth", 1);
    List results = q.list();
    assertEquals(1, results.size());
    c = (Child) results.get(0);
    assertNotNull(c);
    assertNotNull(c.id.parent);
    //FIXME mke it work in unambigious cases
    //		assertNotNull(c.id.parent.id);
    //		assertEquals(p.id.getFirstName(), c.id.parent.id.getFirstName());
    s.delete(c);
    s.delete(c.id.parent);
    tx.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Query(org.hibernate.Query) ArrayList(java.util.ArrayList) List(java.util.List) 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