Questions tagged [jpql]
The Java Persistence Query Language (JPQL) is a platform-independent object-oriented query language defined as part of the Java Persistence API specification.
3,354
questions
2
votes
1
answer
29
views
Is there a way to prevent JPQL's FUNCTION from returning an object of type java.lang.Object?
I have the following JPQL query running in a Payara Micro 5.2022.2 application.
TypedQuery<UserDto> query = entityManager.createQuery(
"SELECT new UserDto((FUNCTION('COALESCE', (select ...
-1
votes
0
answers
19
views
Select one row with same id and match value in another column from another table
I'm currently working on a Spring Boot Webapp where I want to retreive tasks with JPA.
A Task can have multiple requirements and my customer creates requirement_answers which are connected to his ...
0
votes
1
answer
34
views
Why is Right Join not supported by Hibernate and JPA?
When I try to do a Right Join - I get exception java.lang.UnsupportedOperationException: RIGHT JOIN not supported. My Hibernate version is 5.2+ and I am using JPA Criteria API for the Join.
On ...
-1
votes
0
answers
13
views
My jpql query (get mapping) isn't working, I want to filter, search, sorting, pagination. In this query work only paging part
filter, sort, and search part isn't working. Works only paging part:
0
votes
1
answer
27
views
Hibernate: number of batches
The maximum number of packages is specified in the settings.
hibernate.jdbc.batch_size
Is it possible to find out how many batches (and what size) were used for any database operation while the ...
0
votes
1
answer
60
views
JPQL query for select parent Entity having @OneToMany relation with Child Entity, containing optional search parameters
I have two entities, Recipes and Ingredient:
Recipes looks like:
public class Recipes {
private Long id;
private String name;
private Integer serveCount;
private RecipesType type;
...
0
votes
0
answers
29
views
Case on Where Clause of JPQL is not Working
This is my code:
@Query("SELECT m from BankAccount m " +
"inner join BankBranch br on br.id = m.bankBranch.id " +
"inner join Bank bn on bn.id = m....
0
votes
1
answer
21
views
How to formulate JPQL query with or without parameter?
For example take this jpql query -
@Query("SELECT account.name, account.type From AccountEntity account WHERE account.id=:accountId")
getAccountNameById(@Param(accountId) int accountId); //i ...
0
votes
0
answers
30
views
How to select fetched List<SomeEntity> in criteria api?
I have 2 entities with the LAZY @ManyToMany relationship, which are mapped through guest_2_maintenance table: [order_id],[guest_id],[maintenance_id],[order_timestamp]
@Entity
public class Guest {
@...
1
vote
1
answer
28
views
Spring Boot custom query order by aliased aggregate column
I have a table like this called my_objects:
| code | description | open | closed |
+ ---- + ----------- + ---- + ------ +
| 1 | first | 0 | 1 |
| 1 | first | 1 | 0 |
|...
0
votes
1
answer
21
views
How to use JPQL join on unidirectional one to many relationship
Here are my entities:
@Entity
public class Author {
@Id
private Long id;
//...
}
and
@Entity
public class Book {
@Id
private Long id;
@ManyToOne(optional = true)
@...
0
votes
0
answers
18
views
Is it possible to use SQL syntax like FROM DUAL in JPA?
I am trying to create an independent project regardless of the type of DB using JPQL's @Query .
How do I implement the syntax below in JPA?
SELECT MY_SEQ.NEXTVAL FROM DUAL
-1
votes
2
answers
51
views
Hibernate mapping non-entity classes. org.hibernate.MappingException: Unknown entity: java.time.LocalDateTime
I have a table [order_id, guest_id, maintenance_id, order_timestamp], and I want to select list of timestamps, when the guest_id ordered maintenance_id.
I simply tried to select LocalDateTime with the ...
-1
votes
1
answer
82
views
JPQL query returns faulty data [duplicate]
I have troubles with my JPQL/SQL query which returns me faulty data.
Query looks like that:
public interface ReviewRepository extends JpaRepository<Review,Long> {
@Query(value = "SELECT ...
2
votes
2
answers
112
views
Criteria API and JPQL API with GROUP BY and GROUP_CONCAT with DISTINCT / ORDER BY / SEPERATOR Support?
Using JPA Criteria API, I want to group by a column and join the values of another column.
For example, the below is the sql approach and I am looking for the equivalent criteria query (and jpql query)...
1
vote
1
answer
48
views
Spring Data JPA: JPQL query for many to many relationship using inner join?
I have three entities with many to many relationship between them.
Packages <--> join table <--> ProtectedItems <--> join table <--> ContentItems.
I want to query all Packages ...
0
votes
0
answers
12
views
Get enum variable in jpql
I'm trying to get the status variable from this enum :
public enum Topic {
NotPublished(100),
Published(101);
public final Integer status ;
Topic(Integer status) {
this....
1
vote
2
answers
56
views
SELECT DISTINCT rows FROM one table HAVING MIN(value) FROM another table
I have one table (table1) with columns:
ID
NAME
1
A
2
B
3
C
4
D
and another table (table2) with columns:
ID
table1.ID
DATE
STATUS
1
1
21-JUL-2020
INACTIVE
2
1
22-JUL-2022
ACTIVE
3
1
23-JUL-...
0
votes
0
answers
23
views
CASE expression in JPQL
In my SpringBoot project I have CrudRepository with next method:
public interface LoanRequestRepository extends CrudRepository<LoanRequest, UUID> {
@Query(
value = "select &...
0
votes
1
answer
55
views
How to solve Cannot delete or update a parent row: a foreign key constraint fails?
I want to delete user on the basis of phone number. So I made a custom query to delete that particular user. But getting error that cannot delete or update foreign key. So below is my user entity. ...
0
votes
1
answer
30
views
Using list as a positional parameter in JPA query
I want to know if it's possible to pass in a list as a parameter in native queries.
When search up online, an article in Baeldung has exactly what I want to do:
Collection-Valued Positional Parameters ...
2
votes
0
answers
19
views
How to add multiple Standard SQL functions within JPQL
Is it possible to add multiple SQL functions within JPQL ? (Spring Boot application)
By using MetadataBuilderContributor I succeded to add only one.
Is there any way to add more ?
Current code:
public ...
-1
votes
2
answers
28
views
JPA/JPQL automatic method query generation
I have a co-worker that just blew my mind. We have a Java 11/Spring Boot/Hibernate/JPA app talking to a MySQL DB. Apparently JPA JPQL (or something similar to that) is capable of -- but only if you ...
0
votes
0
answers
33
views
Wrong syntax near LIKE clause in MariaDB
I have a syntax error near the like clause, but I assume it's because of the functions I used on the same line.
(:#{#criteria.nameWithCompany} is null " +
" ...
0
votes
1
answer
49
views
JPQL Query - No constructor taking error?
I have a Card entity class with many columns.
I used dto because I want to get some columns from this Entity.
I created a DTO class and wrote a query to CardRepositoryCustom.
But when I try to run the ...
0
votes
0
answers
34
views
How to apply where clause on nested child in JPA?
I have requirement to apply filter (where clause) on nested child but it is not applying.
I am trying below JPQL but it is not working
@Query("select p from Parent p join p.child c join c....
-1
votes
1
answer
38
views
JPQL update query not working in spring boot application
I am trying to update Student emailId based on the firstName as following.
@Modifying(clearAutomatically = true)//, flushAutomatically = true)
@Query(value = "update Student s set s.emailId=:...
0
votes
1
answer
29
views
JPA query couldn't find the right constructor
So basically I try to get some data of a User by its ID and it has a field with @OneToOne relationship(bidirectional)
When I try to create a query in JpaRepository
with @Query annotation
@Query("...
0
votes
1
answer
18
views
Does a JPQL query work with Entities/Objects in memory and doesn't hit the database?
JPQL is similar to SQL, but operates on objects, attributes and
relationships instead of tables and columns
what does that actualy mean? that when you run a JPQL query ,it works with Entities/Objects ...
0
votes
0
answers
25
views
Java : JQL : how to order by inner object attribute
I am using jdk1.8 and looking for a way to write a jql to order by an attribute of a second level object. For example :
public class contact {
private Integer id;
private String firstName;
...
0
votes
1
answer
21
views
Pass a list of integers to JPQL
The below query is from a Spring boot application using JPA.
How do I pass in a list of integers in place of listOfFacilityIds?
Using a String does not work because facility_id column is an int column....
0
votes
0
answers
20
views
How to give alias in JPQLQuery
I need some help with QueryDSL.
This is my query.
select u.*, u1.email as name1, u2.email as name 2
from users u left join
users u1
on u.created_by = u1.user_id
left join
users u2
...
0
votes
0
answers
37
views
JPQL query on abstract mother class accessing subclasses properties
I'm facing a problem trying to make a JPA repository on an abstract class.
What I'm willing to do is a method that filters, paginates and returnes 3 differents kind of objects in a single list. Some ...
1
vote
0
answers
20
views
Getting "encountered array-valued parameter binding" When Checking To See If A Parameter Is NULL
I'm trying to write a query for a filter using Spring Boot and JPQL. Not all parameters are required and some can be null. I have several parameters and have no problem checking if most of them are ...
1
vote
1
answer
38
views
Is there a way to build Objects from an inner class inside of a SELECT statement in JPQL?
I'm trying to build an object from an inner class inside a SELECT statement in JPQL.
I'm extracting data from an entity and using them to build a DTO. Something like this:
SELECT new project.models....
0
votes
0
answers
12
views
JPQL Query not get field element collection
I 'm trying to write a query , there is such an entity ( want to access the ContactHistory element via JPQL):
The main essence:
@Entity(name = "wld$ContractHistoryWorkProcess")
public class ...
0
votes
0
answers
25
views
Any idea why ids are ignored with JPQL query?
In a JPA repository, the following method is defined:
@Query(
"SELECT s FROM Site s "
+ "LEFT JOIN FETCH s.siteType "
+ "LEFT JOIN FETCH s....
0
votes
0
answers
15
views
jpa java JPQL get the list of entities Type
I would like to retrieve the list of requested entities from a JPQL request
and if I detect a specific one add a filtering criteria
sample
String jpql = "select u.fname, u.lname from **Users** u ...
0
votes
1
answer
19
views
Only add not null parameters to jpa query
I want to add only not null values to the SQL query, I can do using criteria builder using predicate list.
How can i make same approach using JPQL
List<Predicate> criteriaList = new ...
0
votes
0
answers
23
views
How to make JPA JOIN query list giving only one item instead of all items by condition
I have some Entities looks like this. Very abstract:
@Entity
class Man {
@Id
String name;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "name", cascade = CascadeType.ALL)
List<...
0
votes
0
answers
20
views
How works OR in JPQL with few difficult subqueries
I try get my applications with many custom condition. I write two JPQL scripts.
select e from atomika_IrisCaApplication e join e.accesses access on e = access.irisCaApplications where (e.applicant = :...
0
votes
0
answers
17
views
Customizing the Result of JPA with list of objects as parameter to the customized response class constructor
I want to customize the result of JPA. I found lot of articles regarding customizing results on stack overflow but non of them addresses my problem. Suppose I have two entities – Supplier and Item. ...
2
votes
1
answer
50
views
How to select substring on entity column using Spring Data JPA
I have an entity called Note which has an attribute text, and I implemented a JpaRepository as follow:
@Entity
@Data
public class Note {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
...
1
vote
1
answer
56
views
Pagebale & sort by COUNT() with other table - JPA
I've got this query
SELECT t.id,t.title,count(k.id) as likes
FROM topics t
LEFT JOIN topic_like k on t.id = k.topic_id
group by t.id, t.title
ORDER BY likes desc ;
When I try to convert it to the ...
0
votes
1
answer
67
views
when query at JPA - JPQL
My system required to add filters,and I'm wonder if there any query that like this
SELECT *
FROM posts p
when byDate is not null then (where p.createAt BETWEEN :startDate AND :endDate)
when byType is ...
0
votes
0
answers
64
views
Hibernate exception on Java HashMap in JPQL query
Trying to create a query using JPQL which will simulate startsWith().
But exception is produced about fromElement being null during the Spring Boot startup.
org.springframework.data.repository.query....
0
votes
0
answers
7
views
Comples redux selector vs. Simple db query
I'm working on my first redux-project and I was wondering if there is a guideline on deciding choosing between adding a additional database query or a redux selector for getting a very different kind ...
0
votes
1
answer
60
views
Convert SQL to JPQL Spring boot
I'm wondering how to convert this query to JPQL:
SELECT t.id, t.title ,
(select count(l.id) from topic_like l where t.id = l.topic_id) as countt
from topics t;
1
vote
2
answers
63
views
JPA Queries Aggregate function COUNT with two tables
I have two entities: Governor and State with ManyToOne association. I need to get all states where there are/were governors and display their count. I'm using PostgreSQL. It looks like this:
SELECT ...
0
votes
1
answer
11
views
JPQL Fetch All Values From OneToMany Joined Table
I have two tables named Student, and Games. Student Id is the foreign key in the Games table, each student can opt for multiple games(OneToMany relation).
Here I need a JPQL query to fetch students' ...