use of org.hibernate.query.criteria.JpaParameterExpression in project hibernate-orm by hibernate.
the class CompositeParameterTests method testDeTypedInPredicateCriteria.
@Test
public void testDeTypedInPredicateCriteria(SessionFactoryScope scope) {
final HibernateCriteriaBuilder builder = scope.getSessionFactory().getCriteriaBuilder();
final JpaMetamodel jpaMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getJpaMetamodel();
final EntityDomainType entityDescriptor = jpaMetamodel.entity(SimpleEntity.class);
final SingularAttribute attribute = entityDescriptor.getSingularAttribute("composite");
scope.inTransaction((session) -> {
final JpaCriteriaQuery criteria = builder.createQuery(SimpleEntity.class);
final JpaRoot root = criteria.from(entityDescriptor);
final Path attrPath = root.get(attribute);
final JpaParameterExpression parameter = builder.parameter(SimpleComposite.class);
criteria.where(builder.in(attrPath, parameter));
final QueryImplementor query = session.createQuery(criteria);
query.setParameter(parameter, new SimpleComposite());
query.list();
});
}
Aggregations