Search in sources :

Example 6 with RequiresDialect

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

the class HQLTest method test_hql_group_by_example_4.

@Test
@RequiresDialect(H2Dialect.class)
@RequiresDialect(PostgreSQL81Dialect.class)
@RequiresDialect(MySQL5Dialect.class)
public void test_hql_group_by_example_4() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        Call call11 = new Call();
        call11.setDuration(10);
        call11.setTimestamp(Timestamp.from(LocalDateTime.of(2000, 1, 1, 0, 0, 0).toInstant(ZoneOffset.UTC)));
        Phone phone = entityManager.createQuery("select p from Phone p where p.calls is empty ", Phone.class).getResultList().get(0);
        phone.addCall(call11);
        entityManager.flush();
        entityManager.clear();
        List<Object[]> personTotalCallDurations = entityManager.createQuery("select p, sum( c.duration ) " + "from Call c " + "join c.phone p " + "group by p", Object[].class).getResultList();
        assertEquals(2, personTotalCallDurations.size());
    });
}
Also used : Call(org.hibernate.userguide.model.Call) Phone(org.hibernate.userguide.model.Phone) Test(org.junit.Test) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 7 with RequiresDialect

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

the class SQLTest method test_sql_hibernate_entity_associations_query_one_to_many_join_example_2.

@Test
@RequiresDialect(H2Dialect.class)
@RequiresDialect(Oracle8iDialect.class)
@RequiresDialect(PostgreSQL82Dialect.class)
public void test_sql_hibernate_entity_associations_query_one_to_many_join_example_2() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        Session session = entityManager.unwrap(Session.class);
        List<Object[]> tuples = session.createSQLQuery("SELECT * " + "FROM Phone ph " + "JOIN phone_call c ON c.phone_id = ph.id").addEntity("phone", Phone.class).addJoin("c", "phone.calls").list();
        for (Object[] tuple : tuples) {
            Phone phone = (Phone) tuple[0];
            Call call = (Call) tuple[1];
        }
        assertEquals(2, tuples.size());
    });
}
Also used : Call(org.hibernate.userguide.model.Call) Phone(org.hibernate.userguide.model.Phone) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 8 with RequiresDialect

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

the class SQLTest method test_sql_jpa_entity_associations_named_query_example.

@Test
@RequiresDialect(H2Dialect.class)
@RequiresDialect(Oracle8iDialect.class)
@RequiresDialect(PostgreSQL82Dialect.class)
public void test_sql_jpa_entity_associations_named_query_example() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        List<Object[]> tuples = entityManager.createNamedQuery("find_person_with_phones_by_name").setParameter("name", "J%").getResultList();
        for (Object[] tuple : tuples) {
            Person person = (Person) tuple[0];
            Phone phone = (Phone) tuple[1];
        }
        assertEquals(1, tuples.size());
    });
}
Also used : Phone(org.hibernate.userguide.model.Phone) Person(org.hibernate.userguide.model.Person) Test(org.junit.Test) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 9 with RequiresDialect

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

the class BeanValidationTest method testTitleColumnHasExpectedLength.

@Test
@RequiresDialect(H2Dialect.class)
public void testTitleColumnHasExpectedLength() {
    EntityManager em = getOrCreateEntityManager();
    int len = (Integer) em.createNativeQuery("select CHARACTER_MAXIMUM_LENGTH from INFORMATION_SCHEMA.COLUMNS c where c.TABLE_NAME = 'CUPHOLDER' and c.COLUMN_NAME = 'TITLE'").getSingleResult();
    assertEquals(64, len);
}
Also used : EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 10 with RequiresDialect

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

the class QueryBuilderTest method testMultiselectWithPredicates.

@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-9092")
public void testMultiselectWithPredicates() {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    CriteriaBuilderImpl cb = (CriteriaBuilderImpl) em.getCriteriaBuilder();
    CriteriaQuery<Customer> cq = cb.createQuery(Customer.class);
    Root<Customer> r = cq.from(Customer.class);
    cq.multiselect(r.get(Customer_.id), r.get(Customer_.name), cb.concat("Hello ", r.get(Customer_.name)), cb.isNotNull(r.get(Customer_.age)));
    TypedQuery<Customer> tq = em.createQuery(cq);
    tq.getResultList();
    em.getTransaction().commit();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaBuilderImpl(org.hibernate.query.criteria.internal.CriteriaBuilderImpl) Customer(org.hibernate.jpa.test.metamodel.Customer) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue) 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