use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.
the class CriteriaParameterTests method testMultiValuedParameter.
@Test
public void testMultiValuedParameter(SessionFactoryScope scope) {
scope.inTransaction(session -> {
final CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
final ParameterExpression<Collection> parameter = criteriaBuilder.parameter(Collection.class);
final CriteriaQuery<BasicEntity> criteria = criteriaBuilder.createQuery(BasicEntity.class);
final Root<BasicEntity> root = criteria.from(BasicEntity.class);
final CriteriaBuilder.In<Object> inPredicate = criteriaBuilder.in(root.get("data"));
inPredicate.value(parameter);
criteria.where(inPredicate);
final QueryImplementor<BasicEntity> query = session.createQuery(criteria);
query.setParameter(parameter, Arrays.asList("fe", "fi", "fo", "fum"));
query.list();
});
}
use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.
the class CriteriaParameterTests method testMultiValuedParameterBaseline3.
@Test
public void testMultiValuedParameterBaseline3(SessionFactoryScope scope) {
scope.inTransaction(session -> {
final HibernateCriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
final ParameterExpression<String> parameter = criteriaBuilder.parameter(String.class);
final CriteriaQuery<BasicEntity> criteria = criteriaBuilder.createQuery(BasicEntity.class);
final Root<BasicEntity> root = criteria.from(BasicEntity.class);
final CriteriaBuilder.In<Object> inPredicate = criteriaBuilder.in(root.get("data"), parameter);
criteria.where(inPredicate);
final QueryImplementor<BasicEntity> query = session.createQuery(criteria);
query.setParameter(parameter, "fe");
query.list();
});
}
use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.
the class MultiSelectTests method multiSelectTupleTest.
@Test
public void multiSelectTupleTest(SessionFactoryScope scope) {
scope.inTransaction((session) -> {
final CriteriaBuilder nodeBuilder = session.getFactory().getNodeBuilder();
final CriteriaQuery<Tuple> criteria = nodeBuilder.createTupleQuery();
final Root<BasicEntity> root = criteria.from(BasicEntity.class);
final EntityType<BasicEntity> model = root.getModel();
criteria.multiselect(root.get(model.getDeclaredSingularAttribute("id", Integer.class)), root.get(model.getDeclaredSingularAttribute("data", String.class)));
final List<Tuple> results = session.createQuery(criteria).list();
assertThat(results).hasSize(1);
final Tuple firstResult = results.get(0);
assertThat(firstResult.get(0)).isEqualTo(1);
assertThat(firstResult.get(1)).isEqualTo("abc");
});
}
use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.
the class MultiSelectTests method typedArrayTest.
@Test
public void typedArrayTest(SessionFactoryScope scope) {
scope.inTransaction((session) -> {
final CriteriaBuilder nodeBuilder = session.getFactory().getNodeBuilder();
final CriteriaQuery<Object[]> criteria = nodeBuilder.createQuery(Object[].class);
final Root<BasicEntity> root = criteria.from(BasicEntity.class);
final EntityType<BasicEntity> model = root.getModel();
criteria.select(nodeBuilder.array(root.get(model.getDeclaredSingularAttribute("id", Integer.class)), root.get(model.getDeclaredSingularAttribute("data", String.class))));
final List<Object[]> results = session.createQuery(criteria).list();
assertThat(results).hasSize(1);
final Object[] firstResult = results.get(0);
assertThat(firstResult[0]).isEqualTo(1);
assertThat(firstResult[1]).isEqualTo("abc");
});
}
use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.
the class MultiSelectTests method typedTupleTest.
@Test
public void typedTupleTest(SessionFactoryScope scope) {
scope.inTransaction((session) -> {
final CriteriaBuilder nodeBuilder = session.getFactory().getNodeBuilder();
final CriteriaQuery<Tuple> criteria = nodeBuilder.createQuery(Tuple.class);
final Root<BasicEntity> root = criteria.from(BasicEntity.class);
final EntityType<BasicEntity> model = root.getModel();
criteria.select(nodeBuilder.tuple(root.get(model.getDeclaredSingularAttribute("id", Integer.class)), root.get(model.getDeclaredSingularAttribute("data", String.class))));
final List<Tuple> results = session.createQuery(criteria).list();
assertThat(results).hasSize(1);
final Tuple firstResult = results.get(0);
assertThat(firstResult.get(0)).isEqualTo(1);
assertThat(firstResult.get(1)).isEqualTo("abc");
});
}
Aggregations