use of org.hibernate.Transaction 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();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class SubclassTest method testEmbeddedSuperclass.
@Test
public void testEmbeddedSuperclass() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Plane p = new Plane();
//sic
p.setAlive(true);
p.setAltitude(10000);
p.setMetricAltitude(3000);
p.setNbrOfSeats(150);
p.setSerial("0123456789");
s.persist(p);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
p = (Plane) s.get(Plane.class, p.getId());
assertNotNull(p);
assertEquals(true, p.isAlive());
assertEquals(150, p.getNbrOfSeats());
assertEquals(10000, p.getAltitude());
assertEquals("0123456789", p.getSerial());
assertFalse(3000 == p.getMetricAltitude());
s.delete(p);
tx.commit();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class ManyToManyTest method testReferencedColumnNameToSuperclass.
@Test
public void testReferencedColumnNameToSuperclass() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
BuildingCompany comp = new BuildingCompany();
comp.setFoundedIn(new Date());
comp.setName("Builder century corp.");
s.persist(comp);
Building building = new Building();
building.setCompany(comp);
s.persist(building);
s.flush();
s.clear();
building = (Building) s.get(Building.class, building.getId());
assertEquals(comp.getName(), building.getCompany().getName());
tx.rollback();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class ManyToManyTest method testJoinedSubclassManyToMany.
@Test
public void testJoinedSubclassManyToMany() throws Exception {
Session s = openSession();
Zone a = new Zone();
InspectorPrefixes ip = new InspectorPrefixes("dgi");
Transaction tx = s.beginTransaction();
s.save(a);
s.save(ip);
ip.getAreas().add(a);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
ip = (InspectorPrefixes) s.get(InspectorPrefixes.class, ip.getId());
assertNotNull(ip);
assertEquals(1, ip.getAreas().size());
assertEquals(a.getId(), ip.getAreas().get(0).getId());
s.delete(ip);
s.delete(ip.getAreas().get(0));
tx.commit();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class ManyToManyTest method testOrderByEmployee.
@Test
public void testOrderByEmployee() throws Exception {
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
Employer employer = new Employer();
Employee employee1 = new Employee();
employee1.setName("Emmanuel");
Employee employee2 = new Employee();
employee2.setName("Alice");
s.persist(employee1);
s.persist(employee2);
Set erColl = new HashSet();
Collection eeColl = new ArrayList();
Collection eeColl2 = new ArrayList();
erColl.add(employee1);
erColl.add(employee2);
eeColl.add(employer);
eeColl2.add(employer);
employer.setEmployees(erColl);
employee1.setEmployers(eeColl);
employee2.setEmployers(eeColl2);
s.flush();
s.clear();
employer = (Employer) s.get(Employer.class, employer.getId());
assertNotNull(employer);
assertNotNull(employer.getEmployees());
assertEquals(2, employer.getEmployees().size());
Employee eeFromDb = (Employee) employer.getEmployees().iterator().next();
assertEquals(employee2.getName(), eeFromDb.getName());
tx.rollback();
s.close();
}
Aggregations