A type-safe, portable API for defining queries for entities - similar to JPQL
Questions tagged [jpa-criteria]
117 questions
2
votes
2 answers
Multi-Column Search with Spring JPA Specifications
I want to create a multi field search in a Spring-Boot back-end. How to do this with a Specification ?
Environment
Springboot
Hibernate
Gradle
Intellij
The UI in the front end is a Jquery Datatable. Each column allows a single string search term…

Radika Moonesinghe
- 361
- 2
- 6
- 17
2
votes
1 answer
Criteria API not in @ElementCollection
With Permission being an enumeration, is it possible to select all users without a certain permission using JPA Criteria API:
@Entity
public class User {
@ElementCollection
@CollectionTable(joinColumns = @JoinColumn(name = "USER_ID"))
…

Imperative
- 3,138
- 2
- 25
- 40
2
votes
2 answers
How can I left join two unrelated tables using JPA Criteria?
Here I have two tables users and orders, users has two fields first_name and last_name, and orders has a field full_name. For some reason, I cannot change the database schema.
Now I have a query:
SELECT u.* FROM users u LEFT JOIN orders o ON…

haohaolee
- 677
- 1
- 9
- 16
2
votes
3 answers
JPA Criteria Query GROUP and COUNT over subquery
Given the following SQL structure of MY_TABLE:
GROUP_LABEL | FILE | TOPIC
-----------------------------
group A | 1.pdf | topic A
group A | 1.pdf | topic B
group A | 2.pdf | topic A
group B | 2.pdf | topic B
My task is to get this…

justus
- 584
- 1
- 7
- 19
2
votes
1 answer
JPA Criteria Query - How to join on only a subclass of the association entity type?
I'm using Spring, Hibernate and the JPA Criteria API.
Let's say I have a Vehicle class hierarchy and a Tire class. Each Vehicle can have multiple Tires.
Vehicle -- Tanker, Motorcylce
Tire
I want to query for small tires that are on Tankers with a…

Jim Ott
- 725
- 13
- 24
2
votes
1 answer
Does Spring Data JPA crudrepository save method have any return value? If so what does it returns?
public void registerCustomer(Customer cust)
{
customerRepo.save(cust);
}
how can i know that my data is insereted successfully in my above code?

harish
- 143
- 3
- 10
2
votes
1 answer
JPA CriteriaBuilder like on double
I'm trying to retrieve data out of a legacy database.
The column in the table is defined as a DECIMAL(13,0) containing account numbers.
The column data type cannot be changed as it will have a major impact on the legacy system. Essentially all…

albert
- 163
- 1
- 5
2
votes
1 answer
How to properly apply join fetch in JPA Criteria API
I am using JPA Criteria API in a Spring data JPA based application. My service class uses static methods to retrieve Specifications which can then be combined together to form a particular query.…

adeelmahmood
- 2,371
- 8
- 36
- 59
1
vote
1 answer
Using database native functions in blaze persistence queries
CriteriaBuilder cb = cbf.create(em, Tuple.class);
cb.from(Pets.class);
cb.select("petId");
cb.orderByAsc("petId");
cb.where("petId").inExpression("select pet_id from get_authorized_pet_id(5)");
…

Amit Mitra
- 83
- 6
1
vote
1 answer
JPA Criteria Query - Set ehcache region name?
I could enable query caching for jpa criteria using below -
javax.persistence.Query regularQuery = em.createQuery(query);
regularQuery.setHint("org.hibernate.cacheable", true);
I also want to specify the cache name for this query, i tried below but…

samshers
- 1
- 6
- 37
- 84
1
vote
1 answer
JPA CriteriaQuery MultiSelect failing on LEFT Join when using class based DTO. Is there someway to fix this?
With Reference to the Criteria Query API doc
CriteriaQuery multiselect(Selection>... selections)
If the type of the criteria query is CriteriaQuery for some
user-defined class X (i.e., a criteria query object created by passing
a X class argument…

samshers
- 1
- 6
- 37
- 84
1
vote
0 answers
JPA Criteria for MAX id GROUP BY SIGNLOGUUID field (solved)
I am practicing with my first java project...
Developing an application using Spring Boot and Spring Data JPA.
The following are entities:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id", nullable = false,…

Jessie
- 11
- 3
1
vote
2 answers
JPA Criteria API: select count(*) from subquery with joins and group by for pagination implementation
I want to implement a pagination feature in a list of products returned from database. So I need to known the total results of the query.
Database tables are:
PRODUCT TABLE
-----------------------------
ID …

Oscar
- 29
- 5
1
vote
1 answer
How to Order By field List names in Jpa repository
I need to order my selected items by status name sequence. (active <- inactive).
I wrote its SQL query correctly as follows. I need to convert it into jpa repository. please help me.
select * from device
where status in ('active', 'inactive')
order…

Geeth
- 541
- 3
- 12
1
vote
2 answers
JPA CriteriaSepcification IN clause
I'm using SpringBoot 2.2.6 with JPA and I need to do query with IN clause as mentioned in Title. I have try with:
@Override
public Predicate toPredicate(Root root, CriteriaQuery> query, CriteriaBuilder builder) {
List…

CoderJammer
- 599
- 3
- 8
- 27