Search in sources :

Example 41 with SkipForDialect

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

the class FooBarTest method testNewSessionLifecycle.

@SkipForDialect(value = AbstractHANADialect.class, comment = "HANA currently requires specifying table name by 'FOR UPDATE of t1.c1' if there are more than one tables/views/subqueries in the FROM clause")
@Test
public void testNewSessionLifecycle() throws Exception {
    Session s = openSession();
    s.beginTransaction();
    Serializable fid = null;
    try {
        Foo f = new Foo();
        s.save(f);
        fid = s.getIdentifier(f);
        s.getTransaction().commit();
    } catch (Exception e) {
        s.getTransaction().rollback();
        throw e;
    } finally {
        s.close();
    }
    s = openSession();
    s.beginTransaction();
    try {
        Foo f = new Foo();
        s.delete(f);
        s.getTransaction().commit();
    } catch (Exception e) {
        s.getTransaction().rollback();
        throw e;
    } finally {
        s.close();
    }
    s = openSession();
    s.beginTransaction();
    try {
        Foo f = (Foo) s.load(Foo.class, fid, LockMode.UPGRADE);
        s.delete(f);
        s.flush();
        s.getTransaction().commit();
    } catch (Exception e) {
        s.getTransaction().rollback();
        throw e;
    } finally {
        s.close();
    }
}
Also used : Serializable(java.io.Serializable) TransactionException(org.hibernate.TransactionException) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) HibernateException(org.hibernate.HibernateException) QueryException(org.hibernate.QueryException) SQLException(java.sql.SQLException) LazyInitializationException(org.hibernate.LazyInitializationException) Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 42 with SkipForDialect

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

the class QueryByExampleTest method testJunctionNotExpressionQBE.

@Test
@SkipForDialect(value = SybaseASE15Dialect.class, jiraKey = "HHH-4580")
public void testJunctionNotExpressionQBE() throws Exception {
    deleteData();
    initData();
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Componentizable master = getMaster("hibernate", null, "ope%");
    Criteria crit = s.createCriteria(Componentizable.class);
    Example ex = Example.create(master).enableLike();
    crit.add(Restrictions.or(Restrictions.not(ex), ex));
    List result = crit.list();
    assertNotNull(result);
    assertEquals(2, result.size());
    t.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Example(org.hibernate.criterion.Example) List(java.util.List) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 43 with SkipForDialect

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

the class SQLLoaderTest method testEscapedJDBC.

@Test
@SkipForDialect({ HSQLDialect.class, PostgreSQL81Dialect.class, PostgreSQLDialect.class })
public void testEscapedJDBC() throws HibernateException, SQLException {
    Session session = openSession();
    session.beginTransaction();
    for (Object entity : session.createQuery("from A").list()) {
        session.delete(entity);
    }
    A savedA = new A();
    savedA.setName("Max");
    session.save(savedA);
    B savedB = new B();
    session.save(savedB);
    session.flush();
    int count = session.createQuery("from A").list().size();
    session.getTransaction().commit();
    session.close();
    session = openSession();
    session.beginTransaction();
    Query query;
    if (getDialect() instanceof TimesTenDialect) {
        // TimesTen does not permit general expressions (like UPPER) in the second part of a LIKE expression,
        // so we execute a similar test 
        query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA where {fn ucase(name)} like 'MAX'").addEntity("a", A.class);
    } else {
        query = session.createSQLQuery("select identifier_column as {a.id}, clazz_discriminata as {a.class}, count_ as {a.count}, name as {a.name} from TA where {fn ucase(name)} like {fn ucase('max')}").addEntity("a", A.class);
    }
    List list = query.list();
    assertNotNull(list);
    assertEquals(1, list.size());
    session.getTransaction().commit();
    session.close();
}
Also used : SQLQuery(org.hibernate.SQLQuery) Query(org.hibernate.Query) TimesTenDialect(org.hibernate.dialect.TimesTenDialect) ArrayList(java.util.ArrayList) List(java.util.List) Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 44 with SkipForDialect

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

the class SQLLoaderTest method testFindSimpleBySQL.

@Test
@SkipForDialect(MySQLDialect.class)
public void testFindSimpleBySQL() throws Exception {
    Session session = openSession();
    session.beginTransaction();
    Category s = new Category();
    s.setName(String.valueOf(nextLong++));
    session.save(s);
    session.flush();
    Query query = session.createSQLQuery("select s.category_key_col as {category.id}, s.name as {category.name}, s.\"assign-able-id\" as {category.assignable} from {category} s").addEntity("category", Category.class);
    List list = query.list();
    assertNotNull(list);
    assertTrue(list.size() > 0);
    assertTrue(list.get(0) instanceof Category);
    session.getTransaction().commit();
    session.close();
// How do we handle objects with composite id's ? (such as Single)
}
Also used : SQLQuery(org.hibernate.SQLQuery) Query(org.hibernate.Query) ArrayList(java.util.ArrayList) List(java.util.List) Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 45 with SkipForDialect

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

the class BlobLocatorTest method testBoundedBlobLocatorAccess.

@Test
@SkipForDialect(value = TeradataDialect.class, jiraKey = "HHH-6637", comment = "Teradata requires locator to be used in same session where it was created/retrieved")
public void testBoundedBlobLocatorAccess() throws Throwable {
    byte[] original = buildByteArray(BLOB_SIZE, true);
    byte[] changed = buildByteArray(BLOB_SIZE, false);
    byte[] empty = new byte[] {};
    Session s = openSession();
    s.beginTransaction();
    LobHolder entity = new LobHolder();
    entity.setBlobLocator(s.getLobHelper().createBlob(original));
    s.save(entity);
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    entity = s.get(LobHolder.class, entity.getId());
    Assert.assertEquals(BLOB_SIZE, entity.getBlobLocator().length());
    assertEquals(original, extractData(entity.getBlobLocator()));
    s.getTransaction().commit();
    s.close();
    // test mutation via setting the new clob data...
    if (getDialect().supportsLobValueChangePropogation()) {
        s = openSession();
        s.beginTransaction();
        entity = (LobHolder) s.byId(LobHolder.class).with(LockOptions.UPGRADE).load(entity.getId());
        entity.getBlobLocator().truncate(1);
        entity.getBlobLocator().setBytes(1, changed);
        s.getTransaction().commit();
        s.close();
        s = openSession();
        s.beginTransaction();
        entity = (LobHolder) s.byId(LobHolder.class).with(LockOptions.UPGRADE).load(entity.getId());
        assertNotNull(entity.getBlobLocator());
        Assert.assertEquals(BLOB_SIZE, entity.getBlobLocator().length());
        assertEquals(changed, extractData(entity.getBlobLocator()));
        entity.getBlobLocator().truncate(1);
        entity.getBlobLocator().setBytes(1, original);
        s.getTransaction().commit();
        s.close();
    }
    // test mutation via supplying a new clob locator instance...
    s = openSession();
    s.beginTransaction();
    entity = (LobHolder) s.byId(LobHolder.class).with(LockOptions.UPGRADE).load(entity.getId());
    assertNotNull(entity.getBlobLocator());
    Assert.assertEquals(BLOB_SIZE, entity.getBlobLocator().length());
    assertEquals(original, extractData(entity.getBlobLocator()));
    entity.setBlobLocator(s.getLobHelper().createBlob(changed));
    s.getTransaction().commit();
    s.close();
    // test empty blob
    s = openSession();
    s.beginTransaction();
    entity = s.get(LobHolder.class, entity.getId());
    Assert.assertEquals(BLOB_SIZE, entity.getBlobLocator().length());
    assertEquals(changed, extractData(entity.getBlobLocator()));
    entity.setBlobLocator(s.getLobHelper().createBlob(empty));
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    entity = s.get(LobHolder.class, entity.getId());
    if (entity.getBlobLocator() != null) {
        Assert.assertEquals(empty.length, entity.getBlobLocator().length());
        assertEquals(empty, extractData(entity.getBlobLocator()));
    }
    s.delete(entity);
    s.getTransaction().commit();
    s.close();
}
Also used : Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Aggregations

SkipForDialect (org.hibernate.testing.SkipForDialect)87 Test (org.junit.Test)86 Session (org.hibernate.Session)66 Transaction (org.hibernate.Transaction)36 List (java.util.List)26 ArrayList (java.util.ArrayList)20 TestForIssue (org.hibernate.testing.TestForIssue)16 EntityManager (javax.persistence.EntityManager)15 Query (javax.persistence.Query)11 Item (org.hibernate.jpa.test.Item)10 Query (org.hibernate.Query)7 Parameter (javax.persistence.Parameter)6 BigDecimal (java.math.BigDecimal)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 SQLQuery (org.hibernate.SQLQuery)4 ScrollableResults (org.hibernate.ScrollableResults)4 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 Date (java.util.Date)3 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)3