Skip to content
Advertisement

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 org.springframework.data.jpa.domain.Specification 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

JPA Criteria builder for dynamic query

I have to write a method where I pass it some arguments and depending on which arguments are empty it modifies the query I need to execute at the end. E.g. if I want to select from a table Customer that has an ID, name, surname and address the starting query would be SELECT * FROM Customer WHERE ID=myId AND

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

JPA Criteria multiselect with fetch

I have following model: Now I would like to query only columns: id, name, shortName and mentor which referes to User entity (not complete entity, because it has many other properties and I would like to have best performance). When I write query: I have following exception: Query before exception: I know that I can replace fetch with join but

Advertisement