Search in sources :

Example 31 with SkipForDialect

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

the class DynamicFilterTest method testSqlSyntaxOfFiltersWithUnions.

@Test
@SkipForDialect(value = { SybaseASE15Dialect.class, IngresDialect.class })
public void testSqlSyntaxOfFiltersWithUnions() {
    Session session = openSession();
    session.enableFilter("unioned");
    session.createQuery("from Category").list();
    session.close();
}
Also used : Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 32 with SkipForDialect

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

the class ASTParserLoadingTest method testCast.

@Test
@SkipForDialect(value = { MySQLDialect.class, DB2Dialect.class })
public void testCast() {
    Session session = openSession();
    Transaction txn = session.beginTransaction();
    session.createQuery("from Human h where h.nickName like 'G%'").list();
    session.createQuery("from Animal a where cast(a.bodyWeight as string) like '1.%'").list();
    session.createQuery("from Animal a where cast(a.bodyWeight as integer) = 1").list();
    txn.commit();
    session.close();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 33 with SkipForDialect

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

the class CriteriaHQLAlignmentTest method testCountReturnValues.

@Test
@SkipForDialect(value = Oracle8iDialect.class, comment = "Cannot count distinct over multiple columns in Oracle")
public void testCountReturnValues() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Human human1 = new Human();
    human1.setName(new Name("John", 'Q', "Public"));
    human1.setNickName("Johnny");
    s.save(human1);
    Human human2 = new Human();
    human2.setName(new Name("John", 'A', "Doe"));
    human2.setNickName("Johnny");
    s.save(human2);
    Human human3 = new Human();
    human3.setName(new Name("John", 'A', "Doe"));
    human3.setNickName("Jack");
    s.save(human3);
    Human human4 = new Human();
    human4.setName(new Name("John", 'A', "Doe"));
    s.save(human4);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    Long count = (Long) s.createQuery("select count( * ) from Human").uniqueResult();
    assertEquals(4, count.longValue());
    s.clear();
    count = (Long) s.createCriteria(Human.class).setProjection(Projections.rowCount()).uniqueResult();
    assertEquals(4, count.longValue());
    s.clear();
    count = (Long) s.createQuery("select count( nickName ) from Human").uniqueResult();
    assertEquals(3, count.longValue());
    s.clear();
    count = (Long) s.createCriteria(Human.class).setProjection(Projections.count("nickName")).uniqueResult();
    assertEquals(3, count.longValue());
    s.clear();
    count = (Long) s.createQuery("select count( distinct nickName ) from Human").uniqueResult();
    assertEquals(2, count.longValue());
    s.clear();
    count = (Long) s.createCriteria(Human.class).setProjection(Projections.count("nickName").setDistinct()).uniqueResult();
    assertEquals(2, count.longValue());
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    try {
        count = (Long) s.createQuery("select count( distinct name ) from Human").uniqueResult();
        if (!getDialect().supportsTupleDistinctCounts()) {
            fail("expected SQLGrammarException");
        }
        assertEquals(2, count.longValue());
    } catch (SQLGrammarException ex) {
        if (!getDialect().supportsTupleDistinctCounts()) {
        // expected
        } else {
            throw ex;
        }
    } finally {
        t.rollback();
        s.close();
    }
    s = openSession();
    t = s.beginTransaction();
    try {
        count = (Long) s.createCriteria(Human.class).setProjection(Projections.count("name").setDistinct()).uniqueResult();
        if (!getDialect().supportsTupleDistinctCounts()) {
            fail("expected SQLGrammarException");
        }
        assertEquals(2, count.longValue());
    } catch (SQLGrammarException ex) {
        if (!getDialect().supportsTupleDistinctCounts()) {
        // expected
        } else {
            throw ex;
        }
    } finally {
        t.rollback();
        s.close();
    }
    s = openSession();
    t = s.beginTransaction();
    count = (Long) s.createQuery("select count( distinct name.first ) from Human").uniqueResult();
    assertEquals(1, count.longValue());
    s.clear();
    count = (Long) s.createCriteria(Human.class).setProjection(Projections.count("name.first").setDistinct()).uniqueResult();
    assertEquals(1, count.longValue());
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    try {
        count = (Long) s.createQuery("select count( name ) from Human").uniqueResult();
        if (!getDialect().supportsTupleCounts()) {
            fail("expected SQLGrammarException");
        }
        assertEquals(1, count.longValue());
    } catch (SQLGrammarException ex) {
        if (!getDialect().supportsTupleCounts()) {
        // expected
        } else {
            throw ex;
        }
    } catch (PersistenceException e) {
        SQLGrammarException cause = assertTyping(SQLGrammarException.class, e.getCause());
        if (!getDialect().supportsTupleCounts()) {
        // expected
        } else {
            throw e;
        }
    } finally {
        t.rollback();
        s.close();
    }
    s = openSession();
    t = s.beginTransaction();
    try {
        count = (Long) s.createCriteria(Human.class).setProjection(Projections.count("name")).uniqueResult();
        if (!getDialect().supportsTupleCounts()) {
            fail("expected SQLGrammarException");
        }
        assertEquals(1, count.longValue());
    } catch (SQLGrammarException ex) {
        if (!getDialect().supportsTupleCounts()) {
        // expected
        } else {
            throw ex;
        }
    } finally {
        t.rollback();
        s.close();
    }
    s = openSession();
    t = s.beginTransaction();
    s.createQuery("delete from Human").executeUpdate();
    t.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) SQLGrammarException(org.hibernate.exception.SQLGrammarException) PersistenceException(javax.persistence.PersistenceException) Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 34 with SkipForDialect

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

the class DeleteWithSubqueryTest method testDeleteMemberOf.

@Test
@TestForIssue(jiraKey = "HHH-8318")
@SkipForDialect(value = MySQLDialect.class, comment = "Cannot use Attrvalue in the delete and from clauses simultaneously.")
public void testDeleteMemberOf() {
    final String qry = "delete Attrvalue aval where aval.id in ( " + "select val2.id from Employee e, Employeegroup eg, Attrset aset, Attrvalue val2 " + "where eg.id = e.employeegroup.id " + "and aset.id = e.attrset.id " + "and val2 member of aset.attrvalues)";
    Session s = openSession();
    s.getTransaction().begin();
    s.createQuery(qry).executeUpdate();
    s.getTransaction().commit();
    s.close();
}
Also used : Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 35 with SkipForDialect

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

the class ASTParserLoadingTest method testComponentParameterBinding.

@Test
@TestForIssue(jiraKey = "HHH-1774")
@SkipForDialect(value = IngresDialect.class, comment = "Subselects are not supported within select target lists in Ingres", jiraKey = "HHH-4970")
public void testComponentParameterBinding() {
    Session s = openSession();
    s.beginTransaction();
    Order.Id oId = new Order.Id("1234", 1);
    // control
    s.createQuery("from Order o where o.customer.name =:name and o.id = :id").setParameter("name", "oracle").setParameter("id", oId).list();
    // this is the form that caused problems in the original case...
    s.createQuery("from Order o where o.id = :id and o.customer.name =:name ").setParameter("id", oId).setParameter("name", "oracle").list();
    s.getTransaction().commit();
    s.close();
}
Also used : Order(org.hibernate.test.cid.Order) Id(org.hibernate.test.cid.LineItem.Id) Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

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