use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class CascadeTest method testDetach.
@Test
public void testDetach() {
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
Tooth tooth = new Tooth();
Mouth mouth = new Mouth();
s.persist(mouth);
s.persist(tooth);
tooth.mouth = mouth;
mouth.teeth = new ArrayList<Tooth>();
mouth.teeth.add(tooth);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
mouth = (Mouth) s.get(Mouth.class, mouth.id);
assertNotNull(mouth);
assertEquals(1, mouth.teeth.size());
tooth = mouth.teeth.iterator().next();
s.evict(mouth);
assertFalse(s.contains(tooth));
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
s.delete(s.get(Mouth.class, mouth.id));
tx.commit();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class CascadeTest method testPersist.
@Test
public void testPersist() {
Session s;
Transaction tx;
s = openSession();
Tooth tooth = new Tooth();
Tooth leftTooth = new Tooth();
tooth.leftNeighbour = leftTooth;
s.persist(tooth);
tx = s.beginTransaction();
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
leftTooth = (Tooth) s.get(Tooth.class, leftTooth.id);
assertNotNull(leftTooth);
tx.commit();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class CascadeToEmbeddedManyToOneTest method testPersistCascadeToEmbedded.
@Test
public void testPersistCascadeToEmbedded() {
Session sess = openSession();
try {
final Transaction trx = sess.beginTransaction();
try {
PersonPair personPair = new PersonPair(new Person("PERSON NAME 1"), new Person("PERSON NAME 2"));
sess.persist(new CodedPairHolder("CODE", personPair));
sess.flush();
} finally {
trx.rollback();
}
} finally {
sess.close();
}
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class CascadeToEmbeddedManyToOneTest method testPersistCascadeToSetOfEmbedded.
@Test
public void testPersistCascadeToSetOfEmbedded() {
Session sess = openSession();
try {
final Transaction trx = sess.beginTransaction();
try {
final Set<PersonPair> setOfPairs = new HashSet<PersonPair>();
setOfPairs.add(new PersonPair(new Person("PERSON NAME 1"), new Person("PERSON NAME 2")));
sess.persist(new CodedPairSetHolder("CODE", setOfPairs));
sess.flush();
} finally {
trx.rollback();
}
} finally {
sess.close();
}
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class AccessTest method testEmbeddableExplicitAccessStrategy.
@Test
public void testEmbeddableExplicitAccessStrategy() throws Exception {
Square square = new Square();
Position pos = new Position(10, 15);
square.setPosition(pos);
Session s = openSession();
s.persist(square);
Transaction tx = s.beginTransaction();
tx.commit();
s.clear();
tx = s.beginTransaction();
square = (Square) s.get(Square.class, square.getId());
assertEquals(10, square.getPosition().x);
try {
square.getPosition().getX();
fail();
} catch (RuntimeException e) {
// success
}
s.delete(square);
tx.commit();
s.close();
}
Aggregations