Search in sources :

Example 31 with RequiresDialect

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

the class ASTParserLoadingTest method testBooleanPredicate.

@Test
@TestForIssue(jiraKey = "HHH-8699")
// For now, restrict to H2.  Selecting w/ predicate functions cause issues for too many dialects.
@RequiresDialect(value = H2Dialect.class, jiraKey = "HHH-9052")
public void testBooleanPredicate() {
    final Session session = openSession();
    session.getTransaction().begin();
    final Constructor constructor = new Constructor();
    session.save(constructor);
    session.getTransaction().commit();
    session.clear();
    Constructor.resetConstructorExecutionCount();
    session.getTransaction().begin();
    final Constructor result = (Constructor) session.createQuery("select new Constructor( c.id, c.id is not null, c.id = c.id, c.id + 1, concat( c.id, 'foo' ) ) from Constructor c where c.id = :id").setParameter("id", constructor.getId()).uniqueResult();
    session.getTransaction().commit();
    assertEquals(1, Constructor.getConstructorExecutionCount());
    assertEquals(new Constructor(constructor.getId(), true, true, constructor.getId() + 1, constructor.getId() + "foo"), result);
    session.close();
}
Also used : Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 32 with RequiresDialect

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

the class OrderByTest method testCriteriaNullsFirstLast.

@Test
@TestForIssue(jiraKey = "HHH-465")
@RequiresDialect(value = { H2Dialect.class, MySQLDialect.class, SQLServer2008Dialect.class }, comment = "By default H2 places NULL values first, so testing 'NULLS LAST' expression. " + "For MySQL and SQL Server 2008 testing overridden Dialect#renderOrderByElement(String, String, String, NullPrecedence) method. " + "MySQL and SQL Server 2008 does not support NULLS FIRST / LAST syntax at the moment, so transforming the expression to 'CASE WHEN ...'.")
public void testCriteriaNullsFirstLast() {
    Session session = openSession();
    // Populating database with test data.
    session.getTransaction().begin();
    Zoo zoo1 = new Zoo(null);
    Zoo zoo2 = new Zoo("Warsaw ZOO");
    session.persist(zoo1);
    session.persist(zoo2);
    session.getTransaction().commit();
    session.clear();
    session.getTransaction().begin();
    Criteria criteria = session.createCriteria(Zoo.class);
    criteria.addOrder(org.hibernate.criterion.Order.asc("name").nulls(NullPrecedence.LAST));
    Iterator<Zoo> iterator = (Iterator<Zoo>) criteria.list().iterator();
    Assert.assertEquals(zoo2.getName(), iterator.next().getName());
    Assert.assertNull(iterator.next().getName());
    session.getTransaction().commit();
    session.clear();
    // Cleanup data.
    session.getTransaction().begin();
    session.delete(zoo1);
    session.delete(zoo2);
    session.getTransaction().commit();
    session.close();
}
Also used : Iterator(java.util.Iterator) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 33 with RequiresDialect

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

the class OrderByTest method testNullsFirstLastSpawnMultipleColumns.

@Test
@TestForIssue(jiraKey = "HHH-465")
@RequiresDialect(value = { H2Dialect.class, MySQLDialect.class, SQLServer2008Dialect.class }, comment = "By default H2 places NULL values first, so testing 'NULLS LAST' expression. " + "For MySQL and SQL Server 2008 testing overridden Dialect#renderOrderByElement(String, String, String, NullPrecedence) method. " + "MySQL and SQL Server 2008 does not support NULLS FIRST / LAST syntax at the moment, so transforming the expression to 'CASE WHEN ...'.")
public void testNullsFirstLastSpawnMultipleColumns() {
    Session session = openSession();
    // Populating database with test data.
    session.getTransaction().begin();
    Zoo zoo = new Zoo();
    zoo.setName("Berlin ZOO");
    Visitor visitor1 = new Visitor(null, null);
    Visitor visitor2 = new Visitor(null, "Antoniak");
    Visitor visitor3 = new Visitor("Lukasz", "Antoniak");
    zoo.getVisitors().add(visitor1);
    zoo.getVisitors().add(visitor2);
    zoo.getVisitors().add(visitor3);
    session.save(zoo);
    session.save(visitor1);
    session.save(visitor2);
    session.save(visitor3);
    session.getTransaction().commit();
    session.clear();
    session.getTransaction().begin();
    zoo = (Zoo) session.get(Zoo.class, zoo.getId());
    Iterator<Visitor> iterator = zoo.getVisitors().iterator();
    Assert.assertEquals(3, zoo.getVisitors().size());
    Assert.assertEquals(visitor3, iterator.next());
    Assert.assertEquals(visitor2, iterator.next());
    Assert.assertEquals(visitor1, iterator.next());
    session.getTransaction().commit();
    session.clear();
    // Cleanup data.
    session.getTransaction().begin();
    session.delete(visitor1);
    session.delete(visitor2);
    session.delete(visitor3);
    session.delete(zoo);
    session.getTransaction().commit();
    session.close();
}
Also used : Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 34 with RequiresDialect

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

the class ComponentTest method testComponentQueryMethodNoParensFailureExpected.

@Test
@RequiresDialect(value = SybaseASE15Dialect.class)
@FailureExpected(jiraKey = "HHH-3150")
public void testComponentQueryMethodNoParensFailureExpected() {
    // Sybase should translate "current_timestamp" in HQL to "getdate()";
    // This fails currently due to HHH-3510. The following test should be
    // deleted and testComponentQueries() should be updated (as noted
    // in that test case) when HHH-3510 is fixed.
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Employee emp = new Employee();
    emp.setHireDate(new Date());
    emp.setPerson(new Person());
    emp.getPerson().setName("steve");
    emp.getPerson().setDob(new Date());
    s.save(emp);
    s.createQuery("from Employee e where e.person = ('steve', current_timestamp)").list();
    s.delete(emp);
    t.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Date(java.util.Date) Session(org.hibernate.Session) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 35 with RequiresDialect

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

the class SQLTest method test_sql_jpa_entity_associations_query_one_to_many_join_example.

@Test
@RequiresDialect(H2Dialect.class)
@RequiresDialect(Oracle8iDialect.class)
@RequiresDialect(PostgreSQL82Dialect.class)
public void test_sql_jpa_entity_associations_query_one_to_many_join_example() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        List<Phone> phones = entityManager.createNativeQuery("SELECT * " + "FROM Phone ph " + "JOIN phone_call c ON c.phone_id = ph.id", Phone.class).getResultList();
        for (Phone phone : phones) {
            List<Call> calls = phone.getCalls();
        }
        assertEquals(2, phones.size());
    });
}
Also used : Call(org.hibernate.userguide.model.Call) Phone(org.hibernate.userguide.model.Phone) Test(org.junit.Test) RequiresDialect(org.hibernate.testing.RequiresDialect)

Aggregations

RequiresDialect (org.hibernate.testing.RequiresDialect)36 Test (org.junit.Test)34 Session (org.hibernate.Session)18 TestForIssue (org.hibernate.testing.TestForIssue)13 EntityManager (javax.persistence.EntityManager)9 RequiresDialectFeature (org.hibernate.testing.RequiresDialectFeature)7 Callable (java.util.concurrent.Callable)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 Transaction (org.hibernate.Transaction)6 HashMap (java.util.HashMap)5 Phone (org.hibernate.userguide.model.Phone)5 LockTimeoutException (javax.persistence.LockTimeoutException)4 List (java.util.List)3 LockOptions (org.hibernate.LockOptions)3 FailureExpected (org.hibernate.testing.FailureExpected)3 Call (org.hibernate.userguide.model.Call)3 Query (javax.persistence.Query)2 QueryTimeoutException (javax.persistence.QueryTimeoutException)2 MetadataSources (org.hibernate.boot.MetadataSources)2 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)2