Search in sources :

Example 71 with SkipForDialect

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

the class BulkManipulationTest method testInsertWithSelectListUsingJoins.

@Test
@SkipForDialect(value = CUBRIDDialect.class, comment = "As of verion 8.4.1 CUBRID doesn't support temporary tables. This test fails with" + "HibernateException: cannot doAfterTransactionCompletion multi-table deletes using dialect not supporting temp tables")
public void testInsertWithSelectListUsingJoins() {
    // this is just checking parsing and syntax...
    Session s = openSession();
    s.beginTransaction();
    s.createQuery("insert into Animal (description, bodyWeight) select h.description, h.bodyWeight from Human h where h.mother.mother is not null").executeUpdate();
    s.createQuery("insert into Animal (description, bodyWeight) select h.description, h.bodyWeight from Human h join h.mother m where m.mother is not null").executeUpdate();
    s.createQuery("delete from Animal").executeUpdate();
    s.getTransaction().commit();
    s.close();
}
Also used : Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 72 with SkipForDialect

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

the class CoalesceTest method HHH_10463_NullInCoalesce.

@Test
@SkipForDialect(jiraKey = "HHH-10463", value = PostgreSQL81Dialect.class)
@SkipForDialect(jiraKey = "HHH-10463", value = Oracle8iDialect.class)
public void HHH_10463_NullInCoalesce() {
    doInHibernate(this::sessionFactory, session -> {
        Query query = session.createQuery("from Person p where p.name = coalesce(:name, p.name) ");
        query.setParameter("name", null);
        List<Person> resultList = query.getResultList();
        assertThat(resultList, hasItem(person));
    });
}
Also used : Query(org.hibernate.query.Query) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 73 with SkipForDialect

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

the class BulkManipulationTest method testDeleteWithMetadataWhereFragments.

@Test
@SkipForDialect(value = CUBRIDDialect.class, comment = "As of verion 8.4.1 CUBRID doesn't support temporary tables. This test fails with" + "HibernateException: cannot doAfterTransactionCompletion multi-table deletes using dialect not supporting temp tables")
public void testDeleteWithMetadataWhereFragments() throws Throwable {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    // Note: we are just checking the syntax here...
    s.createQuery("delete from Bar").executeUpdate();
    s.createQuery("delete from Bar where barString = 's'").executeUpdate();
    t.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 74 with SkipForDialect

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

the class HQLTest method testRowValueConstructorSyntaxInInListBeingTranslated.

@Test
@SkipForDialect(value = { Oracle8iDialect.class, AbstractHANADialect.class, PostgreSQL81Dialect.class, MySQLDialect.class })
public void testRowValueConstructorSyntaxInInListBeingTranslated() {
    QueryTranslatorImpl translator = createNewQueryTranslator("from LineItem l where l.id in (?)");
    assertInExist("'in' should be translated to 'and'", false, translator);
    translator = createNewQueryTranslator("from LineItem l where l.id in ?");
    assertInExist("'in' should be translated to 'and'", false, translator);
    translator = createNewQueryTranslator("from LineItem l where l.id in (('a1',1,'b1'),('a2',2,'b2'))");
    assertInExist("'in' should be translated to 'and'", false, translator);
    translator = createNewQueryTranslator("from Animal a where a.id in (?)");
    assertInExist("only translated tuple has 'in' syntax", true, translator);
    translator = createNewQueryTranslator("from Animal a where a.id in ?");
    assertInExist("only translated tuple has 'in' syntax", true, translator);
    translator = createNewQueryTranslator("from LineItem l where l.id in (select a1 from Animal a1 left join a1.offspring o where a1.id = 1)");
    assertInExist("do not translate sub-queries", true, translator);
}
Also used : QueryTranslatorImpl(org.hibernate.hql.internal.ast.QueryTranslatorImpl) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 75 with SkipForDialect

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

the class FooBarTest method testRefresh.

@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 testRefresh() throws Exception {
    final Session s = openSession();
    s.beginTransaction();
    Foo foo = new Foo();
    s.save(foo);
    s.flush();
    s.doWork(new AbstractWork() {

        @Override
        public void execute(Connection connection) throws SQLException {
            final String sql = "update " + getDialect().openQuote() + "foos" + getDialect().closeQuote() + " set long_ = -3";
            Statement st = connection.createStatement();
            st.executeUpdate(sql);
        }
    });
    s.refresh(foo);
    assertEquals(Long.valueOf(-3l), foo.getLong());
    assertEquals(LockMode.READ, s.getCurrentLockMode(foo));
    s.refresh(foo, LockMode.UPGRADE);
    if (getDialect().supportsOuterJoinForUpdate()) {
        assertEquals(LockMode.UPGRADE, s.getCurrentLockMode(foo));
    }
    s.delete(foo);
    s.getTransaction().commit();
    s.close();
}
Also used : SQLException(java.sql.SQLException) AbstractWork(org.hibernate.jdbc.AbstractWork) Statement(java.sql.Statement) Connection(java.sql.Connection) 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