use of jakarta.persistence.criteria.ParameterExpression in project hibernate-orm by hibernate.
the class CriteriaGetParametersTest method testGetParameters.
@Test
public void testGetParameters(EntityManagerFactoryScope scope) {
scope.inEntityManager(entityManager -> {
final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
final CriteriaQuery<Person> query = criteriaBuilder.createQuery(Person.class);
final Root<Person> person = query.from(Person.class);
query.select(person);
query.where(criteriaBuilder.equal(person.get("age"), 30));
final Set<ParameterExpression<?>> parameters = query.getParameters();
entityManager.createQuery(query).getResultList();
assertThat(parameters, notNullValue());
assertTrue(parameters.isEmpty());
});
}
use of jakarta.persistence.criteria.ParameterExpression in project hibernate-orm by hibernate.
the class BasicCriteriaUsageTest method testParameterCollection.
@Test
public void testParameterCollection() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Wall> criteria = em.getCriteriaBuilder().createQuery(Wall.class);
Root<Wall> from = criteria.from(Wall.class);
ParameterExpression param = em.getCriteriaBuilder().parameter(String.class);
SingularAttribute<? super Wall, ?> colorAttribute = em.getMetamodel().entity(Wall.class).getDeclaredSingularAttribute("color");
assertNotNull("metamodel returned null singular attribute", colorAttribute);
Predicate predicate = em.getCriteriaBuilder().equal(from.get(colorAttribute), param);
criteria.where(predicate);
assertEquals(1, criteria.getParameters().size());
em.getTransaction().commit();
em.close();
}
Aggregations