use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class SybaseTimestampVersioningTest method testCollectionVersion.
@Test
@SuppressWarnings({ "unchecked" })
public void testCollectionVersion() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
User steve = new User("steve");
s.persist(steve);
Group admin = new Group("admin");
s.persist(admin);
t.commit();
s.close();
byte[] steveTimestamp = steve.getTimestamp();
s = openSession();
t = s.beginTransaction();
steve = (User) s.get(User.class, steve.getId());
admin = (Group) s.get(Group.class, admin.getId());
steve.getGroups().add(admin);
admin.getUsers().add(steve);
t.commit();
s.close();
assertFalse("owner version not incremented", BinaryType.INSTANCE.isEqual(steveTimestamp, steve.getTimestamp()));
steveTimestamp = steve.getTimestamp();
s = openSession();
t = s.beginTransaction();
steve = (User) s.get(User.class, steve.getId());
steve.getGroups().clear();
t.commit();
s.close();
assertFalse("owner version not incremented", BinaryType.INSTANCE.isEqual(steveTimestamp, steve.getTimestamp()));
s = openSession();
t = s.beginTransaction();
s.delete(s.load(User.class, steve.getId()));
s.delete(s.load(Group.class, admin.getId()));
t.commit();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class TypeParameterTest method deleteData.
private void deleteData() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
s.createQuery("delete from Widget").executeUpdate();
t.commit();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class TypeParameterTest method testLoading.
@Test
public void testLoading() throws Exception {
initData();
Session s = openSession();
Transaction t = s.beginTransaction();
Widget obj = (Widget) s.createQuery("from Widget o where o.string = :string").setString("string", "all-normal").uniqueResult();
assertEquals("Non-Default value incorrectly loaded", obj.getValueOne(), 7);
assertEquals("Non-Default value incorrectly loaded", obj.getValueTwo(), 8);
assertEquals("Non-Default value incorrectly loaded", obj.getValueThree(), 9);
assertEquals("Non-Default value incorrectly loaded", obj.getValueFour(), 10);
obj = (Widget) s.createQuery("from Widget o where o.string = :string").setString("string", "all-default").uniqueResult();
assertEquals("Default value incorrectly loaded", obj.getValueOne(), 1);
assertEquals("Default value incorrectly loaded", obj.getValueTwo(), 2);
assertEquals("Default value incorrectly loaded", obj.getValueThree(), -1);
assertEquals("Default value incorrectly loaded", obj.getValueFour(), -5);
t.commit();
s.close();
deleteData();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class TypeParameterTest method initData.
private void initData() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
Widget obj = new Widget();
obj.setValueOne(7);
obj.setValueTwo(8);
obj.setValueThree(9);
obj.setValueFour(10);
obj.setString("all-normal");
s.save(obj);
obj = new Widget();
obj.setValueOne(1);
obj.setValueTwo(2);
obj.setValueThree(-1);
obj.setValueFour(-5);
obj.setString("all-default");
s.save(obj);
t.commit();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class UnconstrainedTest method testUnconstrained.
@Test
public void testUnconstrained() {
Session session = openSession();
Transaction tx = session.beginTransaction();
Person p = new Person("gavin");
p.setEmployeeId("123456");
session.persist(p);
tx.commit();
session.close();
session = openSession();
tx = session.beginTransaction();
p = (Person) session.get(Person.class, "gavin");
assertNull(p.getEmployee());
p.setEmployee(new Employee("123456"));
tx.commit();
session.close();
session = openSession();
tx = session.beginTransaction();
p = (Person) session.get(Person.class, "gavin");
assertTrue(Hibernate.isInitialized(p.getEmployee()));
assertNotNull(p.getEmployee());
session.delete(p);
tx.commit();
session.close();
}
Aggregations