A type-safe, portable API for defining queries for entities - similar to JPQL
Questions tagged [jpa-criteria]
117 questions
0
votes
2 answers
Nested exception is java.lang.ClassCastException: java.lang.String cannot be cast
I am new to spring-data, I have this error java.lang.String cannot be cast to com.example.accessingdatamysql.User and do not know how to fix it! I add the various relevant parts of my code.
The method should output the oldest entry (via timestamp)…

Jacket
- 353
- 6
- 18
0
votes
2 answers
JPA Criteria: Obtain total count just before full result with all columns; reuse Where clause
In JPA Criteria I have a complex query which works. It involves many Joins and a complex Where clause. But right before I run it for the full selection, I need to get a quick COUNT of the full resultset.
I tried to reuse my where clause and all my…

gene b.
- 10,512
- 21
- 115
- 227
0
votes
1 answer
Querying with Timestamps using SpringBoot and JPA Criteria Query in custom repository
How do you query based off timestamps in custom JPA repositories using JPA Criteria Query?
I have a startTime and endTime that I want to use to query for entires with a field time between them, but I need to do this in a custom repository because…

Santi Gallego
- 202
- 1
- 18
0
votes
1 answer
Return ResultSet with intact joins in Hibernate / JPA
I have 2 entities: EntityA and EntityB. They are related with a One To Many relation.
public class EntityA {
@Identifier
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="ID", updatable = false, nullable = false)
private…

Kornelito Benito
- 1,067
- 1
- 17
- 38
0
votes
0 answers
JPA2 criteria query for @OneToMany relation using a hidden column without a field mapping
I have an entity Instrument with these fields:
@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumn(referencedColumnName = "instrumentId", nullable = false)
public Set getSymbols()…

Aaron Digulla
- 321,842
- 108
- 597
- 820
0
votes
1 answer
JPA aggregation on aggregated subquery result
I have following JPA entity (getters, setter and non relevant fields omitted):
@Entity
@Table(name = "transaction")
public class Transaction {
@Id
@GeneratedValue
@Column(name = "id")
private Long id;
@Column(name = "start_date", nullable =…

Daniil
- 913
- 8
- 19
0
votes
1 answer
Criteria API with Unidirectional relationship
I have three entities. I need construct Criteria API where i can select project if unique users will be more than userCount variable.
@Entity
@Table(name = "client")
public class Client {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
…

Дмитрий Бокач
- 44
- 2
0
votes
1 answer
Multiselect in jpa criteria is throwing illegal argument exception when foreign key column is null
Join locationTypeJoin = root.join(Location_.LOCATION_TYPE);
Join addressJoin = root.join(Location_.ADDRESS, JoinType.LEFT);
Join stateJoin = addressJoin.join(Address_.STATE,…

Ruby Kannan
- 251
- 1
- 6
0
votes
0 answers
JPA - Reusing Specifications from different classes
Let's say I have 2 classes defined this way
class A{
private String name;
}
class B{
private A a;
private String bla;
}
And also have predicates for A and B, like this
public static Specification hasName(String name) {
…

Camilo Casadiego
- 907
- 3
- 9
- 33
0
votes
0 answers
How to implement subquery in JPA criteria while joining table views to remove duplicates
I was working on an aggregation query where we have two table views with name Task and Member.
For the Member view we can have duplicates. ie: id field of member view is not unique.
So when we do group by to find combinations with task name and an…

Sachin
- 1,675
- 2
- 19
- 42
0
votes
1 answer
Jpa Criteria equals Predicate for a table's String property (with newLine character '\n') doesn't work when in MySQL Workbench it works
as the title suggests I am having a problem trying to use JPA Criteria with Spring Boot for a specific case.
Generally everything works but trying to search for stored data with a String property having newLine character embedded ( \n ) doesn't seem…

Alexandros Markovits
- 163
- 4
- 19
0
votes
1 answer
Spring Data JPA Specifications Calling
I followed this tutorial to get Spring Data JPA Specifications: https://dzone.com/articles/using-spring-data-jpa-specification
It worked to implement that for me, but I can't call the specifications methods to search for them. I want to have them in…

CptDayDreamer
- 1,526
- 6
- 25
- 61
0
votes
0 answers
IN clause using Example in Spring Data JPA
I am using the findAll passing Example and Pageable.. How can I use IN clause? for example in a Class I have a property location. i want to pass 2 location as parameters.
Thanks.
Here is the findAll im using:
public Page…

Joseph Move
- 69
- 1
- 9
0
votes
1 answer
Spring JPA Specification : How to sort on aggregate function using specification
Error is thrown when we are trying to sort on aggregated column COUNT.
For Example : Requirement is to form below query using specification. But, it is not returning single entity as result. Rather, it's join of tables.
Sort on SQL Query required…

Vaibhav Sawant
- 341
- 1
- 7
- 22
0
votes
2 answers
I am looking for an alternative to Specifications for the given scenario
I am calling findall() method of the JpaRepository as following
Service
on.findall(specificationsbuilder.getspecifications(params), paegable obj)
specificationsbuilder.getspecifications(param)
returns specifications
My question is if…

Sarthak
- 188
- 1
- 2
- 14