use of javax.persistence.criteria.CriteriaBuilder in project hibernate-orm by hibernate.
the class MappedSuperclassComponentWithCollectionTest method testSizeExpressionForTheElementCollectionPropertyOfASubComponent.
@Test
public void testSizeExpressionForTheElementCollectionPropertyOfASubComponent() {
TransactionUtil.doInJPA(this::entityManagerFactory, entityManager -> {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Leader> query = builder.createQuery(Leader.class);
Root<Leader> root = query.from(Leader.class);
query.where(builder.equal(builder.size(root.get("information").get("infoContactDetail").get("phones")), 1));
final List<Leader> results = entityManager.createQuery(query).getResultList();
assertThat(results.size(), is(1));
});
}
use of javax.persistence.criteria.CriteriaBuilder in project hibernate-orm by hibernate.
the class MappedSuperclassComponentWithCollectionTest method testSizeExpressionForTheOneToManyPropertyOfAComponent.
@Test
public void testSizeExpressionForTheOneToManyPropertyOfAComponent() {
TransactionUtil.doInJPA(this::entityManagerFactory, entityManager -> {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Manager> query = builder.createQuery(Manager.class);
Root<Manager> root = query.from(Manager.class);
query.where(builder.equal(builder.size(root.get("projects").get("previousProjects")), 2));
final List<Manager> results = entityManager.createQuery(query).getResultList();
assertThat(results.size(), is(1));
});
}
use of javax.persistence.criteria.CriteriaBuilder in project hibernate-orm by hibernate.
the class LoadGraphFindByIdTest method createTypedQuery.
private TypedQuery<User> createTypedQuery(EntityManager em) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<User> cq = cb.createQuery(User.class);
Root<User> root = cq.from(User.class);
cq.where(cb.equal(root.get("id"), 1L));
TypedQuery<User> tq = em.createQuery(cq);
tq.setHint("javax.persistence.loadgraph", createEntityGraph(em));
return tq;
}
use of javax.persistence.criteria.CriteriaBuilder in project hibernate-orm by hibernate.
the class QueryLockingTest method testCriteriaWithPessimisticLock.
@Test
@TestForIssue(jiraKey = "HHH-11376")
@RequiresDialect(SQLServerDialect.class)
public void testCriteriaWithPessimisticLock() {
TransactionUtil.doInJPA(this::entityManagerFactory, entityManager -> {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Person> criteria = builder.createQuery(Person.class);
Root<Person> personRoot = criteria.from(Person.class);
ParameterExpression<Long> personIdParameter = builder.parameter(Long.class);
personRoot.fetch("parent", JoinType.LEFT);
criteria.select(personRoot).where(builder.equal(personRoot.get("id"), personIdParameter));
final List<Person> resultList = entityManager.createQuery(criteria).setParameter(personIdParameter, 1L).setLockMode(LockModeType.PESSIMISTIC_WRITE).getResultList();
resultList.isEmpty();
});
}
use of javax.persistence.criteria.CriteriaBuilder in project metacat by Netflix.
the class IdEntityDaoImpl method get.
@Override
public List<T> get(final Iterable<Long> ids) {
final EntityManager entityManager = em.get();
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<T> criteriaQuery = cb.createQuery(getEntityClass());
final Root<T> root = criteriaQuery.from(getEntityClass());
criteriaQuery.where(root.get("id").in(Lists.newArrayList(ids)));
return entityManager.createQuery(criteriaQuery).getResultList();
}
Aggregations