Skip to content

Tag: criteria-api

Criteria API join with filter

So I am trying to replace the following native SQL with JPA Criteria Api: or The entities look a bit like this: I implemented a I can use together with a JpaSpecificationExecutor like: and But I only get one side of the join/select like: when I do: How do I add the table to the select here? So the

What is the difference between CriteriaBuilder.createQuery and EntityManager.createQuery?

Let’s say I have the code, like: Can some please explain why we are using two createQuery() methods and what is the difference between them? Answer CriteriaBuilder#createQuery(Class<T> resultClass) creates CriteriaQuery<T> and EntityManager#createQuery(CriteriaQuery<T> criteriaQuery) creates TypedQuery<T>. TL;DR: These two types are not the alternatives of each other, they rather serve the different purposes: CriteriaQuery<T> is used to programmatically define query, instead