use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.
the class DDLWithoutCallbackTest method testMinAndMaxChecksGetApplied.
@Test
@RequiresDialectFeature(DialectChecks.SupportsColumnCheck.class)
public void testMinAndMaxChecksGetApplied() {
MinMax minMax = new MinMax(1);
assertDatabaseConstraintViolationThrown(minMax);
minMax = new MinMax(11);
assertDatabaseConstraintViolationThrown(minMax);
minMax = new MinMax(5);
Session s = openSession();
Transaction tx = s.beginTransaction();
s.persist(minMax);
s.flush();
tx.rollback();
s.close();
}
use of org.hibernate.testing.RequiresDialectFeature 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();
}
use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.
the class BasicHibernateAnnotationsTest method testSerialized.
@Test
@RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class)
public void testSerialized() throws Exception {
Forest forest = new Forest();
forest.setName("Shire");
Country country = new Country();
country.setName("Middle Earth");
forest.setCountry(country);
Set<Country> near = new HashSet<Country>();
country = new Country();
country.setName("Mordor");
near.add(country);
country = new Country();
country.setName("Gondor");
near.add(country);
country = new Country();
country.setName("Eriador");
near.add(country);
forest.setNear(near);
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
s.persist(forest);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
forest = (Forest) s.get(Forest.class, forest.getId());
assertNotNull(forest);
country = forest.getCountry();
assertNotNull(country);
assertEquals(country.getName(), forest.getCountry().getName());
near = forest.getNear();
assertTrue("correct number of nearby countries", near.size() == 3);
for (Iterator iter = near.iterator(); iter.hasNext(); ) {
country = (Country) iter.next();
String name = country.getName();
assertTrue("found expected nearby country " + name, (name.equals("Mordor") || name.equals("Gondor") || name.equals("Eriador")));
}
tx.commit();
s.close();
}
use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.
the class BasicHibernateAnnotationsTest method testType.
@Test
@RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class)
public void testType() throws Exception {
Forest f = new Forest();
f.setName("Broceliande");
String description = "C'est une enorme foret enchantee ou vivais Merlin et toute la clique";
f.setLongDescription(description);
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
s.persist(f);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
f = (Forest) s.get(Forest.class, f.getId());
assertNotNull(f);
assertEquals(description, f.getLongDescription());
s.delete(f);
tx.commit();
s.close();
}
use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.
the class BasicHibernateAnnotationsTest method testVersioning.
@Test
@RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class)
@SkipForDialect(value = TeradataDialect.class, comment = "One transaction hangs the other")
public void testVersioning() 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();
Session parallelSession = openSession();
Transaction parallelTx = parallelSession.beginTransaction();
s = openSession();
tx = s.beginTransaction();
forest = (Forest) parallelSession.get(Forest.class, forest.getId());
Forest reloadedForest = (Forest) s.get(Forest.class, forest.getId());
reloadedForest.setLength(11);
assertNotSame(forest, reloadedForest);
tx.commit();
s.close();
forest.setLength(22);
try {
parallelTx.commit();
fail("All optimistic locking should have make it fail");
} catch (OptimisticLockException e) {
if (parallelTx != null)
parallelTx.rollback();
} finally {
parallelSession.close();
}
s = openSession();
tx = s.beginTransaction();
s.delete(s.get(Forest.class, forest.getId()));
tx.commit();
s.close();
}
Aggregations