use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class VersionedLobTest method testVersionUnchangedPrimitiveByteArray.
@Test
public void testVersionUnchangedPrimitiveByteArray() throws Exception {
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
VersionedCompiledCode cc = createCompiledCode();
int codeSize = 5;
byte[] full = new byte[codeSize];
for (int i = 0; i < codeSize; i++) {
full[i] = (byte) (1 + i);
}
cc.setFullCode(full);
s.persist(cc);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
VersionedCompiledCode recompiled = getCompiledCodeClass().cast(s.get(getCompiledCodeClass(), getId(cc)));
assertEquals(recompiled.getFullCode()[codeSize - 1], cc.getFullCode()[codeSize - 1]);
assertEquals(recompiled.getVersion(), Integer.valueOf(0));
s.flush();
assertEquals(recompiled.getVersion(), Integer.valueOf(0));
s.delete(recompiled);
tx.commit();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class VersionedLobTest method testVersionUnchangedPrimitiveCharArray.
@Test
public void testVersionUnchangedPrimitiveCharArray() throws Exception {
VersionedBook book = createBook();
Editor editor = new Editor();
editor.setName("O'Reilly");
book.setEditor(editor);
book.setCode2(new char[] { 'r' });
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
s.persist(book);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
VersionedBook loadedBook = getBookClass().cast(s.get(getBookClass(), getId(book)));
assertEquals(loadedBook.getVersion(), Integer.valueOf(0));
s.flush();
assertEquals(loadedBook.getVersion(), Integer.valueOf(0));
s.delete(loadedBook);
tx.commit();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class ManyToManyTest method testCanUseCriteriaQuery.
@Test
public void testCanUseCriteriaQuery() throws Exception {
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
Store fnac = new Store();
fnac.setName("Fnac");
Supplier emi = new Supplier();
emi.setName("Emmanuel");
emi.setSuppStores(new HashSet<Store>());
fnac.setSuppliers(new HashSet<Supplier>());
fnac.getSuppliers().add(emi);
emi.getSuppStores().add(fnac);
s.persist(fnac);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
List result = s.createCriteria(Supplier.class).createAlias("suppStores", "s").add(Restrictions.eq("s.name", "Fnac")).list();
assertEquals(1, result.size());
tx.commit();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class EagerIndexedCollectionTest method testTemporalKeyMap.
@Test
public void testTemporalKeyMap() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Atmosphere atm = new Atmosphere();
atm.colorPerDate.put(new Date(1234567000), "red");
s.persist(atm);
s.flush();
s.clear();
atm = (Atmosphere) s.get(Atmosphere.class, atm.id);
assertEquals(1, atm.colorPerDate.size());
final Date date = atm.colorPerDate.keySet().iterator().next();
final long diff = new Date(1234567000).getTime() - date.getTime();
assertTrue("24h diff max", diff >= 0 && diff < 24 * 60 * 60 * 1000);
tx.rollback();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class EagerIndexedCollectionTest method testEntityKeyElementTarget.
@Test
public void testEntityKeyElementTarget() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Atmosphere atm = new Atmosphere();
Gas o2 = new Gas();
o2.name = "oxygen";
atm.composition.put(o2, 94.3);
s.persist(o2);
s.persist(atm);
s.flush();
s.clear();
atm = (Atmosphere) s.get(Atmosphere.class, atm.id);
assertTrue(Hibernate.isInitialized(atm.composition));
assertEquals(1, atm.composition.size());
assertEquals(o2.name, atm.composition.keySet().iterator().next().name);
tx.rollback();
s.close();
}
Aggregations