Search in sources :

Example 6 with RequiresDialectFeature

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();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 7 with RequiresDialectFeature

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();
}
Also used : Transaction(org.hibernate.Transaction) Query(org.hibernate.Query) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 8 with RequiresDialectFeature

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();
}
Also used : Transaction(org.hibernate.Transaction) Iterator(java.util.Iterator) HashSet(java.util.HashSet) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 9 with RequiresDialectFeature

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();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 10 with RequiresDialectFeature

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();
}
Also used : Transaction(org.hibernate.Transaction) OptimisticLockException(javax.persistence.OptimisticLockException) Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Aggregations

RequiresDialectFeature (org.hibernate.testing.RequiresDialectFeature)46 Test (org.junit.Test)45 Session (org.hibernate.Session)34 Transaction (org.hibernate.Transaction)17 TestForIssue (org.hibernate.testing.TestForIssue)10 EntityManager (javax.persistence.EntityManager)8 HashMap (java.util.HashMap)7 RequiresDialect (org.hibernate.testing.RequiresDialect)7 List (java.util.List)6 Callable (java.util.concurrent.Callable)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 Query (org.hibernate.Query)6 LockTimeoutException (javax.persistence.LockTimeoutException)5 ArrayList (java.util.ArrayList)4 QuerySyntaxException (org.hibernate.hql.internal.ast.QuerySyntaxException)4 SkipForDialect (org.hibernate.testing.SkipForDialect)4 Query (javax.persistence.Query)3 BigDecimal (java.math.BigDecimal)2 Map (java.util.Map)2 QueryTimeoutException (javax.persistence.QueryTimeoutException)2