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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations