Search in sources :

Example 11 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 12 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)

Example 13 with RequiresDialectFeature

use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.

the class LobLocatorTest method testStreamResetBeforeParameterBinding.

/**
	 * Specific JDBC drivers (e.g. SQL Server) may not automatically rewind bound input stream
	 * during statement execution. Such behavior results in error message similar to:
	 * {@literal The stream value is not the specified length. The specified length was 4, the actual length is 0.}
	 */
@Test
@TestForIssue(jiraKey = "HHH-8193")
@RequiresDialectFeature(DialectChecks.UsesInputStreamToInsertBlob.class)
public void testStreamResetBeforeParameterBinding() throws SQLException {
    final Session session = openSession();
    session.getTransaction().begin();
    LobHolder entity = new LobHolder(session.getLobHelper().createBlob("blob".getBytes()), session.getLobHelper().createClob("clob"), 0);
    session.persist(entity);
    session.getTransaction().commit();
    final Integer updatesLimit = 3;
    for (int i = 1; i <= updatesLimit; ++i) {
        session.getTransaction().begin();
        entity = (LobHolder) session.get(LobHolder.class, entity.getId());
        entity.setCounter(i);
        entity = (LobHolder) session.merge(entity);
        session.getTransaction().commit();
    }
    session.getTransaction().begin();
    entity = (LobHolder) session.get(LobHolder.class, entity.getId());
    entity.setBlobLocator(session.getLobHelper().createBlob("updated blob".getBytes()));
    entity.setClobLocator(session.getLobHelper().createClob("updated clob"));
    entity = (LobHolder) session.merge(entity);
    session.getTransaction().commit();
    session.clear();
    session.getTransaction().begin();
    checkState("updated blob".getBytes(), "updated clob", updatesLimit, (LobHolder) session.get(LobHolder.class, entity.getId()));
    session.getTransaction().commit();
    session.close();
}
Also used : Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature) TestForIssue(org.hibernate.testing.TestForIssue)

Example 14 with RequiresDialectFeature

use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.

the class ManyToOneReferencedColumnNameTest method testReoverableExceptionInFkOrdering.

@Test
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public void testReoverableExceptionInFkOrdering() throws Exception {
    //SF should not blow up
    Vendor v = new Vendor();
    Item i = new Item();
    ZItemCost ic = new ZItemCost();
    ic.setCost(new BigDecimal(2));
    ic.setItem(i);
    ic.setVendor(v);
    WarehouseItem wi = new WarehouseItem();
    wi.setDefaultCost(ic);
    wi.setItem(i);
    wi.setVendor(v);
    wi.setQtyInStock(new BigDecimal(2));
    Session s = openSession();
    s.getTransaction().begin();
    s.save(i);
    s.save(v);
    s.save(ic);
    s.save(wi);
    s.flush();
    s.getTransaction().rollback();
    s.close();
}
Also used : BigDecimal(java.math.BigDecimal) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 15 with RequiresDialectFeature

use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.

the class CompositeUserTypeTest method testGreaterOrEqualOperator.

/**
	 * Tests the {@code >=} operator on composite types. As long as we don't support it, we need to throw an exception
	 * rather than create a random query.
	 */
@Test
@TestForIssue(jiraKey = "HHH-5946")
@RequiresDialectFeature(value = DialectChecks.DoesNotSupportRowValueConstructorSyntax.class)
public void testGreaterOrEqualOperator() {
    final Session s = openSession();
    try {
        final Query q = s.createQuery("from Transaction where value >= :amount");
        q.setParameter("amount", new MonetoryAmount(BigDecimal.ZERO, Currency.getInstance("USD")));
        q.list();
    } catch (IllegalArgumentException e) {
        assertTyping(QuerySyntaxException.class, e.getCause());
    //expected
    } finally {
        s.close();
    }
}
Also used : Query(org.hibernate.Query) QuerySyntaxException(org.hibernate.hql.internal.ast.QuerySyntaxException) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature) TestForIssue(org.hibernate.testing.TestForIssue)

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