use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.
the class CriteriaParameterTests method testMultiValuedParameterBaseline.
@Test
public void testMultiValuedParameterBaseline(SessionFactoryScope scope) {
scope.inTransaction(session -> {
final CriteriaBuilder 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"));
inPredicate.value("fe");
inPredicate.value("fi");
inPredicate.value("fo");
inPredicate.value("fum");
criteria.where(inPredicate);
final QueryImplementor<BasicEntity> query = session.createQuery(criteria);
query.list();
});
}
use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.
the class CriteriaParameterTests method testNamedParameterBaseline.
@Test
public void testNamedParameterBaseline(SessionFactoryScope scope) {
scope.inTransaction(session -> {
final CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
final ParameterExpression<Collection> parameter = criteriaBuilder.parameter(Collection.class, "datas");
final CriteriaQuery<BasicEntity> criteria = criteriaBuilder.createQuery(BasicEntity.class);
final Root<BasicEntity> root = criteria.from(BasicEntity.class);
Path<?> property = root.get("data");
criteria.where(property.in(parameter));
final QueryImplementor<BasicEntity> query = session.createQuery(criteria);
List<String> parameterValue = new ArrayList<>();
parameterValue.add("fe");
query.setParameter("datas", parameterValue);
query.list();
});
}
use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.
the class CriteriaParameterTests method testMultiValuedParameterBaseline2.
@Test
public void testMultiValuedParameterBaseline2(SessionFactoryScope scope) {
scope.inTransaction(session -> {
final CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
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"));
final ParameterExpression<String> p1 = criteriaBuilder.parameter(String.class);
inPredicate.value(p1);
final ParameterExpression<String> p2 = criteriaBuilder.parameter(String.class);
inPredicate.value(p2);
criteria.where(inPredicate);
final QueryImplementor<BasicEntity> query = session.createQuery(criteria);
query.setParameter(p1, "fe");
query.setParameter(p2, "fi");
query.list();
});
}
use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.
the class CriteriaParameterTests method testParameterBaseline.
@Test
public void testParameterBaseline(SessionFactoryScope scope) {
scope.inTransaction(session -> {
final CriteriaBuilder 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);
criteria.where(criteriaBuilder.equal(root.get("data"), parameter));
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 arrayTupleTest.
@Test
public void arrayTupleTest(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.select((Selection) nodeBuilder.array(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