Search in sources :

Example 6 with Query

use of org.hibernate.query.Query in project OpenClinica by OpenClinica.

the class FormLayoutDao method findByFormLayoutId.

public FormLayout findByFormLayoutId(int formLayoutId) {
    String query = "from " + getDomainClassName() + " form_layout  where form_layout.formLayoutId = :formlayoutid ";
    Query q = getCurrentSession().createQuery(query);
    q.setParameter("formlayoutid", formLayoutId);
    return (FormLayout) q.uniqueResult();
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Query(org.hibernate.query.Query)

Example 7 with Query

use of org.hibernate.query.Query in project hibernate-orm by hibernate.

the class EntityTest method testTemporalType.

@Test
@SkipForDialect(value = Oracle10gDialect.class, comment = "oracle12c returns time in getDate.  For now, skip.")
public void testTemporalType() throws Exception {
    Flight airFrance = doInHibernate(this::sessionFactory, session -> {
        Flight _airFrance = new Flight();
        _airFrance.setId(Long.valueOf(747));
        _airFrance.setName("Paris-Amsterdam");
        _airFrance.setDuration(Long.valueOf(10));
        _airFrance.setDepartureDate(Date.from(LocalDate.of(2005, 06, 21).atStartOfDay(ZoneId.systemDefault()).toInstant()));
        _airFrance.setAlternativeDepartureDate(new GregorianCalendar(2006, 02, 03, 10, 00));
        _airFrance.getAlternativeDepartureDate().setTimeZone(TimeZone.getTimeZone("GMT"));
        _airFrance.setBuyDate(new java.sql.Timestamp(122367443));
        _airFrance.setFactor(25);
        session.persist(_airFrance);
        return _airFrance;
    });
    doInHibernate(this::sessionFactory, session -> {
        Query q = session.createQuery("from Flight f where f.departureDate = :departureDate");
        q.setParameter("departureDate", airFrance.getDepartureDate(), StandardBasicTypes.DATE);
        Flight copyAirFrance = (Flight) q.uniqueResult();
        assertNotNull(copyAirFrance);
        assertEquals(Date.from(LocalDate.of(2005, 06, 21).atStartOfDay(ZoneId.systemDefault()).toInstant()), copyAirFrance.getDepartureDate());
        assertEquals(df.format(airFrance.getBuyDate()), df.format(copyAirFrance.getBuyDate()));
        session.delete(copyAirFrance);
    });
}
Also used : Query(org.hibernate.query.Query) GregorianCalendar(java.util.GregorianCalendar) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 8 with Query

use of org.hibernate.query.Query in project hibernate-orm by hibernate.

the class CoalesceTest method HHH_10463_NullInCoalesce_PostgreSQL_Workaround.

@Test
@RequiresDialect(PostgreSQL81Dialect.class)
public void HHH_10463_NullInCoalesce_PostgreSQL_Workaround() {
    doInHibernate(this::sessionFactory, session -> {
        Query query = session.createQuery("from Person p where p.name = coalesce(cast( :name as string) , p.name) ");
        query.setParameter("name", null);
        List<Person> resultList = query.getResultList();
        assertThat(resultList, hasItem(person));
    });
}
Also used : Query(org.hibernate.query.Query) Test(org.junit.Test) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 9 with Query

use of org.hibernate.query.Query in project hibernate-orm by hibernate.

the class ScrollableTest method testScrollableResults2.

@Test
@TestForIssue(jiraKey = "HHH-10860")
public void testScrollableResults2() {
    final List params = new ArrayList();
    params.add(1L);
    params.add(2L);
    try (Session s = openSession()) {
        final Query query = s.createQuery("from MyEntity e where e.id in (:ids)").setParameter("ids", params).setFetchSize(10);
        try (ScrollableResults scroll = query.scroll()) {
            int i = 0;
            while (scroll.next()) {
                if (i == 0) {
                    assertThat(((MyEntity) scroll.get()[0]).getDescription(), is("entity_1"));
                } else {
                    assertThat(((MyEntity) scroll.get()[0]).getDescription(), is("entity_2"));
                }
                i++;
            }
        }
    }
}
Also used : Query(org.hibernate.query.Query) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ScrollableResults(org.hibernate.ScrollableResults) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 10 with Query

use of org.hibernate.query.Query in project hibernate-orm by hibernate.

the class LobStringTest method testSelectStringLobAnnotatedInHqlQuery.

@Test
@TestForIssue(jiraKey = "HHH-11477")
public void testSelectStringLobAnnotatedInHqlQuery() {
    TransactionUtil.doInHibernate(this::sessionFactory, session -> {
        final Query query = session.createQuery("select t.secondLobField from TestEntity t where LOWER(t.firstLobField) LIKE :value");
        query.setParameter("value", value1);
        final List<String> results = query.list();
        assertThat(results.size(), is(1));
        assertThat(results.get(0), is(value2));
    });
}
Also used : Query(org.hibernate.query.Query) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

Query (org.hibernate.query.Query)157 Test (org.junit.Test)44 Session (org.hibernate.Session)39 List (java.util.List)24 ArrayList (java.util.ArrayList)19 TestForIssue (org.hibernate.testing.TestForIssue)19 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)17 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)17 HashMap (java.util.HashMap)15 Map (java.util.Map)14 NativeQuery (org.hibernate.query.NativeQuery)14 AbstractJPATest (org.hibernate.test.jpa.AbstractJPATest)11 SessionFactory (org.hibernate.SessionFactory)9 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 InvocationHandler (java.lang.reflect.InvocationHandler)7 Method (java.lang.reflect.Method)7 SQLException (java.sql.SQLException)7 Collectors (java.util.stream.Collectors)7 AbstractQueryFacade (org.jboss.tools.hibernate.runtime.common.AbstractQueryFacade)7 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)6