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();
}
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);
});
}
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));
});
}
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++;
}
}
}
}
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));
});
}
Aggregations