A type-safe, portable API for defining queries for entities - similar to JPQL
Questions tagged [jpa-criteria]
117 questions
3
votes
2 answers
Spring JPA Specification Full Text Search with MYSQL
I am attempting to create a full text search using a Spring JPA specification. The query I am trying to accomplish is below.
SELECT * FROM Station WHERE MATCH(Slogan, Description) AGAINST('searchText' IN BOOLEAN MODE);
How do I write this query in…

Sixthpoint
- 1,161
- 3
- 11
- 34
3
votes
2 answers
How to get top results using specifications in spring data jpa?
I am quite new to spring data jpa. I am trying to use specifications while querying database. My question is using crudrepository we can method like :
findTopByUsernameOrderByUpdatedAtDesc(String username);
How can I achieve the same using…

Nakul Kumar
- 325
- 1
- 5
- 11
3
votes
1 answer
JPA lazy OneToOne relation is fetched when loading or querying an entity when it shouldn't? Why?
Given these two entities with a OneToOne relationship (A as owning side holding the B entity id):
@Entity
@Table(name="A")
public class AEntity{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
...
…

codependent
- 23,193
- 31
- 166
- 308
3
votes
0 answers
spring jpa query with pageable, sort and filter and return projection
I am using Spring Data Rest with org.springframework.boot 1.5.2 with hibernate 5.2.9. What i am trying to achieve is a way to use JPA to query with sort, filter, pageable that can return a subset of the entity or return a projection.
Below is the…

bmw34
- 111
- 4
3
votes
2 answers
JPA - Why cast Fetch to Join
Why is it necessary sometimes to cast?
Join a = (Join) Fetch ...
For Example:
Root personRoot = criteriaQuery.from(Person.class);
@SuppressWarnings("unchecked")
Join loanJoin = (Join) personRoot.fetch("loan",…

costajlmpp
- 71
- 1
- 7
3
votes
0 answers
JPA CriteriaBuilder collection operations with an Entity/Object
I am using JPA CriteriaBuilder api for generating queries, i have following set of beans:
Artist(contains the artist data like name, gender, address etc)
Role (contains Roles played by an artist like role id, role type, role description etc)
An…

suraj bahl
- 2,864
- 6
- 31
- 42
2
votes
1 answer
Specify complex sorting criteria when requesting Spring Data JPA repository
I'm requesting paged and sorted data from my database, specified via Pageable with following repository API:
org.springframework.data.jpa.repository.JpaSpecificationExecutor.findAll(Specification filter, Pageable pageable)
Pageable…

PAX
- 1,056
- 15
- 33
2
votes
2 answers
JPA Criteria API "IN" Predicate not working
I need to write the following with JPA Criteria API:
p.id IS NULL AND nv.organizationalstat IN ('EMPLOYEE', 'FELLOW')`
My code is:
List corePredicateInList = Arrays.asList("EMPLOYEE", "FELLOW");
In corePredicateIn =…

gene b.
- 10,512
- 21
- 115
- 227
2
votes
2 answers
How to filter null values in ArrayList
I have a very big code. I faced an issue where at very starting of code, null
gets inserted inside arraylist custlist i.e custlist looks like [null]. And after many lines of code, I had my code changes where I was building up Predicate using…

ASharma7
- 726
- 3
- 8
- 27
2
votes
0 answers
Join two tables on basis of One common column via Hibernate Annotation and JPA criteria Query not working as expected
I have two tables device_data and device_connection. I want to join these two tables on basis of column customerId. Both the tables have customerId column.
DeviceData
import java.io.Serializable;
import java.math.BigInteger;
import…

Khalid Shah
- 3,132
- 3
- 20
- 39
2
votes
0 answers
Subquery SELECT as a field using JPA Criteria API
I have the following SQL query:
select
A.A_ID,
B.Lib,
A.Lib,
C.Lib,
(SELECT count(*) FROM X WHERE A.A_ID = X.A_ID) AS countX,
(SELECT count(*) FROM Y WHERE A.A_ID = Y.A_ID) AS countY,
(SELECT…

Renaud is Not Bill Gates
- 1,684
- 34
- 105
- 191
2
votes
0 answers
how to get the total results count in pagination
I'm trying to get the count of total results from table in spring Data JPA but some how I am getting this error
Query argument pattern not found in the list of parameters provided during query execution.
below is what I tried:
CriteriaQuery…

Developer
- 2,389
- 4
- 11
- 17
2
votes
1 answer
Is there a way to return Specifications for Parent Entity for org.springframework.data.jpa.domain.Specification?
Suppose I have a bidirectional 1-1 association with the Person entity
@Entity
public class Person {
@OneToOne(optional=false)
@JoinColumn(name = "contact_id")
private Contact contact;
// getters/setters/constructors
}
And the Contact…

Sanjeev Maharjan
- 142
- 1
- 9
2
votes
0 answers
Hibernate 5 Criteria Join for One to Many relationship
Code for join Query
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery cquery = builder.createQuery(SchoolTO.class);
Root root = cquery.from(SchoolTO.class);
Join join =…

Santosh Balaji Selvaraj
- 373
- 2
- 16
2
votes
2 answers
JPA Criteria API filter subentities
The code example:
@Entity
public class Event {
@Id
@GeneratedValue
private Long id;
private String name;
@OneToMany(mappedBy="event")
private List actions;
}
@Entity
public class Action {
…

Alexander Kuzmenko
- 529
- 1
- 12
- 32