5,063 questions
0
votes
2
answers
113
views
How to pick the latest record with GROUP BY userId
In my application I want to find the latest duty of each user from 'StaffDuty' table using hibernate query (i.e. HQL). Below is my query.
query = session.createQuery("FROM StaffDuty where deptId....
0
votes
1
answer
26
views
Is there a HQL condition where one object of a set is in a many-to-many relationship in 2025?
I have a Task with a @ManyToMany referenced roles, which specify roles a user must have at least one of, to perform the task. The HQL search should therefore find all tasks that have at least one of ...
0
votes
0
answers
14
views
HQL query returns NULL after session.save(object) and session.flush()
I am creating an enablePackage API code flow in JAVA. I am using the Spring MVC project.
I am facing an issue related to HQL query returning null.
The code logic is as follows:
Foo.class
List<...
3
votes
1
answer
226
views
Silently ignoring "Could not locate named parameter" for param in subquery and pagination
I'm running a JPA non-native query, which returns a custom object.
@Query("""
SELECT
new path.to.CustomObject(
t,
(select id from users where name = :param1)
...
0
votes
1
answer
188
views
Hibernate 6.x - How to register a PostgreSQL function returning a table for use in JPQL?
i'm trying to register a PostgreSQL custom function in Hibernate 6.x so that I can use it directly in JPQL, without relying on native queries.
Scenario
I have a PostgreSQL SQL function that returns a ...
0
votes
0
answers
42
views
NHibernate MismatchedTokenException
I have an HQL query that, every time I run it, throws Antlr.Runtime.MismatchedTokenException: 'A recognition error occurred.'. So far as I can tell, this is because I'm trying to use an entity ...
1
vote
1
answer
38
views
HQL: cast to SIGNED is not known symbol
I need to convert this query to HQL syntax:
SELECT * FROM my_table
GROUP BY `name`
HAVING MIN(ABS(CAST(202000 AS SIGNED) - CAST(step_id AS SIGNED))) = ABS(CAST(202000 AS
SIGNED) - CAST(step_id AS ...
0
votes
1
answer
166
views
HQL Hibernate 6 ORM Query class type on delete statement
I am upgrading an spring boot app (spring-boot-starter-parent) from 2.6.1 to 3.4.1. part of that upgrade is related to the upgrade of hibernate 5 to 6 and specifically hibernate core 6.6.4.Final with ...
0
votes
0
answers
36
views
How to determine if there is an intersection between two HQL wherestatement by code
I have two queries targeting the same table, and I want to determine if the filtering ranges of these two queries intersect, that is, whether the two queries will filter the same data.Even if the ...
3
votes
1
answer
53
views
HQL generate wrong cast
Having a cast like this:
SELECT
CAST(a * 100000000 as big_integer)
FROM
Amount
WHERE
id = :id
Generate this SQL:
prepareStatement(
"select cast(amount0_.\"a\"*100000000 ...
0
votes
0
answers
61
views
HQL ORDER BY query with adding days to date column
I use spring boot, and I want to add specific days to date column in mysql database on hql query order by clause. But which results error when I tried. I need to get results in the order of adding ...
0
votes
0
answers
30
views
Select entity and ids of its surrounding entities
This is my query
It is meant to return the selectedResponse and its next and previous ids. As you can see, the Where clause currently constrains the results. I tried a nested select and CTE, both ...
2
votes
1
answer
33
views
How to get a single entry per non-unique column value?
I have tables in DB and matching entities. I have a table 'products'. Each entry in 'products' has unique 'id' column and 'code', which is not unique, multiple different 'products' may have the same '...
0
votes
0
answers
30
views
Using a Constructor in HQL gives MappingException when using it in repository interface but works fine when using it in service class [duplicate]
According to chapter Using a Constructor in HQL in https://www.baeldung.com/hibernate-query-to-custom-class I should be able to use my DTO constructor in @Query select statement.
However when I try to ...
0
votes
1
answer
99
views
How to check a property in any of multiple column when column value not null
Below are some of the tables in my product app where I need to execute a case statement as per the data values.
class Payment implements Serializable {
@Id
@GeneratedValue(strategy = ...