Questions tagged [criteriaquery]
245 questions
1
vote
1 answer
Hibernate Criteriabuilder Query with part of a compound id
I have a class that I am attempting to query by "userid"
@Entity
@IdClass(CollectionPK.class)
@Table(name="collection", schema="mageduelsusers")
public class Collection{
@Id
@Column(name = "userid")
private int userId;
@Id
@Column(name =…

deadlypandaghost
- 21
- 3
1
vote
0 answers
How to use Specifications to write the subqueries
I am new to specifications and writing queries using criteria builder. I have a little success writing it for very small queries but not for a large query i needed.
class MessageEntity{
long id;
List message_details;
}
class…

CodeHunter
- 33
- 1
- 4
1
vote
3 answers
JPA create count query from existing CriteriaQuery
I have a query with some predicates, I need to count total records for paging.
Currently, what I'm doing is declare 2 roots for the query to get result list (1) and the count query (2), then with each predicate, duplicate it with different root like…

ccr
- 11
- 2
1
vote
0 answers
Java JPA Criteria Query Subquery in SELECT clause using TupleQuery
I'm trying to configure a subquery in the select clause to achieve an SQL equivalent like this:
SELECT
t0.field1 AS a1,
t0.field2 AS a2,
t0.field3 AS a3,
t0.field4 AS a4,
t0.field5 AS a5,
(SELECT COUNT(t1.id) from table1 t1 WHERE…

JMart
- 191
- 3
- 8
1
vote
1 answer
EntityGraph and TypedQuery simultaneously
I'm try to use two Hibernate features simultaneously: EntityGraph and Criteria API TypedQuery but can't resolve how to use them together:
@Override
public List findByFilterEntityGraph(final CustomerFilter filter) {
final EntityManager…

Pavel
- 2,005
- 5
- 36
- 68
1
vote
2 answers
JPA Criteria API generates extra inner join with the use of a subtype class
We have 3 classes Case, Meeting and SpecialMeeting (zie objects below). When we use the JPA Criteria Api in the following way:
static Specification betweenEnddateSpecialMeeting(LocalDate start, LocalDate end) {
return (root, query,…

Andre Torensma
- 13
- 2
1
vote
1 answer
How to use multiple JOINs with CriteriaBuilder to build Predicate?
I have table A that has an attribute that is an entity in table B that in turn is connected to a table C.
The (working) SQL query looks like this:
SELECT a.* from A a
LEFT JOIN B b ON a.b_id=b.id
LEFT JOIN C c ON b.c_id=c.id where…

Eno
- 10,730
- 18
- 53
- 86
1
vote
0 answers
How to write the following sql query using Criteria Builder?
select AVG(EXTRACT(EPOCH FROM ot.end_date -ot.create_date )/3600),count(*), date_trunc('day', ot.update_date)
from ... ot
...
How to write the sql query using Criteria Builder? How to use this epoch in Criteria Query?

mervedev
- 11
- 2
1
vote
0 answers
CriteriaBuilder Parent multiselect with child object
I'm trying Build criteriaQuery with a parent child entities, I need to use multiselect for selected fields for parent and selected fields for child, not able to pull all the children with fields
@Data
@Entity
@NoArgsConstructor
@Table( name =…

pteki
- 11
- 2
1
vote
0 answers
How do I rewrite this particular JPQL query with SELECT MAX() to CriteriaQuery?
I am quite new to JPA and I have encountered a problem with understanding one particular query. I have rewritten in to the CriteriaQuery but the result and the query translated to SQL is not correct.
Background situation: I have a table of store…

Vojtech Hordejcuk
- 11
- 2
1
vote
1 answer
Criteria API deprecated, how to convert ti CriteriaQuery instead?
I am migrating an old existing project to Springboot.
I have following method:
public List findAll(Class> clazz) {
Criteria search = entityManager.unwrap(Session.class).createCriteria(clazz);
List entities = search.list();
return…
user13089222
1
vote
0 answers
Eclipselink problem with subquery in where clause
I have the following structure: (I am using eclipselink 2.6.0)
@Entity
public class A {
@Id
private double id;
...
@OneToMany
private List b;
@OneToMany(mappedBy = "a")
private List c;
...
}
@Entity
public class B {
@Id
private…

user3420018
- 25
- 8
1
vote
0 answers
Hibernate CriteriaBuilder cannot compare 2 time - The data types time and datetime are incompatible in the greater than or equal to operator
I am writing criteria query with compare 2 time.
As I run the service, an exception was thrown:
2020-06-19 19:12:08.688 - WARN 27740 [ault-executor-0] o.h.e.j.s.SqlExceptionHelper : SQL Error: 402, SQLState: S0001
2020-06-19…

Huỳnh Thanh Bình
- 95
- 2
- 9
1
vote
1 answer
Hibernate CriteriaQuery where - ManyToOne field
that's fragment of my Employee entity/class:
@Entity
@Table
public class Employee {
...
@ManyToOne(.....)
@JoinColumn(name="department_id")
private Department department;
}
Now, I want to fetch all Employees from specific Department…

Nickname11
- 501
- 9
- 23
1
vote
0 answers
generated aliases error in spring JPA in criteria query API
public Predicate get_data(String field, String method, String value) throws Exception
{
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(student.class);
Root s =…

Anurag Kumar
- 45
- 5