use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class IdClassTest method testIdClassInSuperclass.
@Test
public void testIdClassInSuperclass() throws Exception {
Tower tower = new Tower();
tower.latitude = 10.3;
tower.longitude = 45.4;
Session s = openSession();
Transaction tx = s.beginTransaction();
s.persist(tower);
s.flush();
s.clear();
Location loc = new Location();
loc.latitude = tower.latitude;
loc.longitude = tower.longitude;
assertNotNull(s.get(Tower.class, loc));
tx.rollback();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class FormulaWithColumnTypesTest method testFormulaAnnotationWithTypeNames.
@Test
@TestForIssue(jiraKey = "HHH-9951")
public void testFormulaAnnotationWithTypeNames() {
Session session = openSession();
Transaction transaction = session.beginTransaction();
DisplayItem displayItem20 = new DisplayItem();
displayItem20.setDisplayCode("20");
DisplayItem displayItem03 = new DisplayItem();
displayItem03.setDisplayCode("03");
DisplayItem displayItem100 = new DisplayItem();
displayItem100.setDisplayCode("100");
session.persist(displayItem20);
session.persist(displayItem03);
session.persist(displayItem100);
transaction.commit();
session.close();
// 1. Default sorting by display code natural ordering (resulting in 3-100-20).
session = openSession();
transaction = session.beginTransaction();
List displayItems = session.createCriteria(DisplayItem.class).addOrder(Order.asc("displayCode")).list();
assertNotNull(displayItems);
assertEquals(displayItems.size(), 3);
assertEquals("03", ((DisplayItem) displayItems.get(0)).getDisplayCode());
assertEquals("100", ((DisplayItem) displayItems.get(1)).getDisplayCode());
assertEquals("20", ((DisplayItem) displayItems.get(2)).getDisplayCode());
transaction.commit();
session.close();
// 2. Sorting by the casted type (resulting in 3-20-100).
session = openSession();
transaction = session.beginTransaction();
List displayItemsSortedByInteger = session.createCriteria(DisplayItem.class).addOrder(Order.asc("displayCodeAsInteger")).list();
assertNotNull(displayItemsSortedByInteger);
assertEquals(displayItemsSortedByInteger.size(), 3);
assertEquals("03", ((DisplayItem) displayItemsSortedByInteger.get(0)).getDisplayCode());
assertEquals("20", ((DisplayItem) displayItemsSortedByInteger.get(1)).getDisplayCode());
assertEquals("100", ((DisplayItem) displayItemsSortedByInteger.get(2)).getDisplayCode());
transaction.commit();
session.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class UnresolvedTypeTest method testAcceptsUnresolvedPropertyTypesIfATargetEntityIsExplicitlySet.
@Test
public void testAcceptsUnresolvedPropertyTypesIfATargetEntityIsExplicitlySet() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Gene item = new Gene();
s.persist(item);
s.flush();
tx.rollback();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class UnresolvedTypeTest method testAcceptsUnresolvedPropertyTypesIfATypeExplicitlySet.
@Test
public void testAcceptsUnresolvedPropertyTypesIfATypeExplicitlySet() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Gene item = new Gene();
item.setState(State.DORMANT);
s.persist(item);
s.flush();
s.clear();
item = (Gene) s.get(Gene.class, item.getId());
assertEquals(State.DORMANT, item.getState());
tx.rollback();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class BasicHibernateAnnotationsTest method testPolymorphism.
@Test
@RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class)
public void testPolymorphism() throws Exception {
Forest forest = new Forest();
forest.setName("Fontainebleau");
forest.setLength(33);
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
s.persist(forest);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
Query query = s.createQuery("from java.lang.Object");
assertEquals(0, query.list().size());
query = s.createQuery("from Forest");
assertTrue(0 < query.list().size());
tx.commit();
s.close();
}
Aggregations