Questions tagged [hql]
For questions concerning "Hibernate Query Language" (HQL), a query language used by Hibernate and NHibernate. Use the tag [hiveql] for questions about Hive Query Language.
4,997
questions
0
votes
0
answers
22
views
Spring boot generates query with sql syntax error
I am building a spring boot backend and trying to solve my Lazy Loading Problems with a Dto or the join fetch solution. I've got the following entity:
@Entity
public class Project implements ...
0
votes
0
answers
23
views
+50
Replacing multiple values in an array in hive
I have a column which contains languages which is displayed in full, I need to change that and send the ISO format.
SELECT id, get_json_object(json_data, '$.languages') AS language from someTable
data ...
0
votes
0
answers
16
views
finding an element in json using get_json_object or json_tuple in hql
Below is the sample json element in my table. i want to only get typ SSN and typ TIN and their respective Id's in my output. I am using below code but i am traversing manually to each iteration and ...
0
votes
1
answer
27
views
Regex expression to put "." after sixth position from right in HQL
I have an requirement to put a dot(.) after 6th character from right to left. The total character length is 15 char.
I have below table:
Tab1
---
Col1 Col2
--- -----
1 000000000000098
2 ...
0
votes
0
answers
18
views
HiveSQL: how to merge lines ?
i have one question about Hive and SQL need to resolve, please help me !
now i have one table like this:
id col1 col2
1 10 100
1 20 100
1 30 200
2 10 100
2 10 200
2 20 200
then i ...
0
votes
1
answer
21
views
When relationship to a X column is null the records are not selected in the HQL statement. (PostgreSQL)
@Query("SELECT new com.api.projection.GarageVehicleRequestLookupProjection" +
"(vr.id, vr.appUser.fullName, vr.appUser.unit.id, vr.appUser.unit.name, vr.createdAt, " +
...
-1
votes
0
answers
60
views
Hibernate eager loading causing n+1 problem
I am writing join query with left join fetch still n+1 queries are loading. The entity classes using are
@Table(name = "TRAVELERS")
@Cacheable(true)
@Audited
public class ...
0
votes
0
answers
16
views
running a echo command in hql not taking up dynamic variable
running a korn shell which passes --hivevar into HQL ,
inside the HQL script i am using below command
!sh echo "successfully completed ${tablename} loading"
but i get output as
successfully ...
1
vote
2
answers
34
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
2
answers
37
views
JPA query check if @Param set is empty or null
I've a complex HQL query which I want to run. One of my params is a Set<Integer> with valid values for the result
something like: select * from table t where t.code IN (Set<Integer>)
This ...
0
votes
1
answer
26
views
Strange HQL Query Behavior When Fetching Data
I call the method below to calculate some values. I supply the agencyID and the integer representation of the month to carry out the calculation.
Map jan = new HashMap();
String a[] = shifts....
0
votes
0
answers
38
views
Hibernate - How to use DetachedCriteria with LEFT JOIN and addOrder()?
I have the below code which worked previously to order the values by displayOrder.
DetachedCriteria criteria = DetachedCriteria.forClass(Parameter.class);
...
criteria.addOrder(Order.asc(&...
0
votes
1
answer
31
views
Is there a better way to write HQL queries in Spring Data JPA that has many conditions?
Below I present a hypothetical scenario where the age of a user is converted to words in user resource and I want to sort the user data based on this new string i.e. eight has the highest priority in ...
0
votes
0
answers
43
views
SQL query is fast but hibernate query in application cause an exception
one of our queries in the java application caused ORA-00028: Your session has been killed
but when I checked the SQL query with our DBA he said it is ok and fast and fetches data under 500 ms but when ...
1
vote
0
answers
41
views
HQL query with column alias and group by
I'm trying to do a complex query with hibernate and HQL, the query logic works in my mysql database
the mysql query is:
SELECT GetTaskStatus(t.due_date, t.completed_date) as status,
count(*) ...
0
votes
1
answer
20
views
how to embed order by string in hql in grails for sorting?
In grails 2 i used to use the following hql
def sortp = ""
if(params.sort){
sortp = "order by r.${params.sort} ${params.order}"
}
def allRegsData = RaceRegistration....
0
votes
4
answers
68
views
Extract last working day of every month in bigquery
Currently I'm using the below code:
SELECT DATE_SUB(example, INTERVAL 1 DAY) ,
FORMAT_DATE("%A", DATE_SUB(example, INTERVAL 1 DAY))
FROM UNNEST(GENERATE_DATE_ARRAY('2013-01-1', '2030-...
0
votes
0
answers
16
views
HQL query with null parameter, is it possible?
I'm trying to write an HQL query like so :
select distinct new com.myproject.entities.MyPerson(person.firstName , person.lastName, person.age, address.streetName) from Person person, Address address
I'...
0
votes
1
answer
25
views
Getting a ClassCastException when trying a join query in Hibernate
This is my tables:
@Entity
@Table(name="Students")
public class Students {
@Id
@Column(name="Student_ID")
private int id;
@Column(name="Student_Name")
private String ...
0
votes
1
answer
60
views
how to pull all records in hive based on another column
If this is what my table looks like below:
my_id my_words my_people my_number
100 need more info? Jim 1
100 now Mary ...
0
votes
1
answer
35
views
Unable to close the Hibernate Session for loading Lazily loaded fields
We are using Hibernate+Spring for a module and we used @ManyToOne(fetch = FetchType.LAZY) on multiple fields in multiple POJOs.
While querying for these POJOs through HQL, I am opening a ...
0
votes
1
answer
25
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....
1
vote
0
answers
38
views
Data not fetching in Hibernate but fetching in SQL with same equal condition
SELECT * FROM <TABLE_NAME> WHERE date_date_time = '2025-04-01 10:16:12' is fetching data from SQL.
But in Hibernate, the same date ('2025-04-01 10:16:12') is not matching with the column and ...
0
votes
1
answer
26
views
What's the source of this HQL query error?
public List<UserDto> getTopUsersForDaysRankedByNumberOfQuestions(Integer daysCount, Integer usersCount) {
return entityManager.createQuery(
"select new com....
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....
1
vote
1
answer
18
views
Why do put @ManyToOne in both table and what does it mean
I know this is very silly question but I am new to hibernate..
I am working on hibernate and In my project I can see there are 2 Entities
Suppose A and B and they relation like
Class A{
@ManyToOne
B b;...
0
votes
1
answer
35
views
How to create @Query() for avg(column) for every n minutes?
I have a postrges query which does that but I cannot translate it into a spring @Query definition:
select AVG(price) as price,date_trunc('hour', created) + date_part('minute', created)::int / 5 * ...
0
votes
0
answers
12
views
How to use uuid_generate_v4() method in HQL query? [duplicate]
@Modifying
@Query(value = "INSERT into RolePermissionMapping (id, roleId, organizationId, permissionId) " +
"SELECT uuid_generate_v4(), :roleId, :organizationId, apm.id &...
0
votes
0
answers
20
views
HQL Query for extracting certain number from a large string
I am trying to extract a certain number in a large string field available in a database table in Hive using HQL. sample and desired output are given below. Please support.
String Sample:
'.....1HGFE......
0
votes
0
answers
19
views
How can i fix the token in hql?
how can i fix this select * error? thank you!!
Query query = em.createQuery("select distinct............");
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: *...
0
votes
2
answers
25
views
how to stop HQL hibernate insert multiple data inserted?
Implementation: HQL hibernate. Im trying to save 1 data but what happen is its saving many data the only i stop it is by result > 1 to NullPointerException. I already put some session.close() ...
0
votes
1
answer
38
views
HQL/ORM hibernate Implementation error Null
Implemenetation: A project with ORM hibernate HQL so i changes my implementation like this https://www.javaguides.net/2019/10/hibernate-query-language-tutorial.html but its giving me error. My old ...
0
votes
0
answers
26
views
How to take the data of 2 tables and map it to an entity
I have 2 tables
Table A
---------------------------
| collection_date | value |
---------------------------
| ... | ... |
---------------------------
Table B
---------------------------
...
0
votes
1
answer
24
views
No results showing for String NULL data in hive
I have an external table in hive which was loaded with some NULL data.
None of the below queries are returning any results:
select * FROM db.table where bankrupt IS NULL;
select * FROM db.table ...
0
votes
1
answer
27
views
Left join with <> condition (not equal to) returns wrong rows
HQL Statement:
String hql = "SELECT DISTINCT track FROM TrackEntity track " +
"LEFT JOIN track.releaseRelations releaseRelation " +
"LEFT JOIN ...
0
votes
1
answer
27
views
HQL query to get one value, with distinct? grouping by?
Im trying to get just one for every c_id. I have the following data:
+---------+---------+------------+---------------------+-------------------+------------+
| c_id | country | birth_date | ...
0
votes
1
answer
93
views
HQL QuerySyntaxException: unexpected AST node
Searched and found a lot of questions about this but nothing for my particular case. I am getting an error on my HQL query, here is the code:
final Query query = session.createQuery(
...
1
vote
1
answer
178
views
How to join results of multiple tables in Spring JPA repository which has same column names
I'm new to Spring and I'm trying to create my first Spring project. I want to create the query to get appointment data with firstName and lastName of a patient as well as firstName and lastName of the ...
0
votes
0
answers
28
views
HQL Named Query how to select the original and all joined values when there is a match in a joined value
@NamedQuery(name = "ValueType.getByPropertyKeyAndValue",
query = "SELECT distinct v FROM ValueTypeEntity v "
+ " LEFT OUTER JOIN FETCH ...
0
votes
0
answers
269
views
Unable to locate appropriate constructor Expected arguments are: java.lang.String
I have been completely unable to get Hibernate with DTOs. Not even very simple object with a single string, it always complains about "Unable to locate appropriate constructor" :(
I started ...
0
votes
1
answer
19
views
Convert a value(string) to timestamp (Input string has unwanted characters) - SQL
I'm trying to convert a value in my table to a timestamp but the value in the table is as below
There's a character 'T' after the date in the string.
GMT_TIME
20210608T111722.837 GMT
1st Goal:
Achieve ...
0
votes
0
answers
25
views
Replace JPA @Query with two queries?
I have one legacy application that uses Spring JPA. THere's one method with @Query annotation. It needs to be replaced with two queries. What's the easiest approach ? THanks.
0
votes
0
answers
47
views
In hibernate UniqueResult() and list() throws NullPointerException
I am expecting a single value or null in call of a NamedQuery where query.list() and query.uniqueResult() returns NullPointerException. I am getting session from SessionFactory and there is no blank ...
1
vote
1
answer
111
views
Implement HQL builder from requirements code
I have this code where I build transaction:
public BooleanBuilder findAllTransactionsByUserId(Long userId, DateTime startDate, DateTime endDate,
String firstName, String lastName, String email) ...
0
votes
0
answers
26
views
Parse string to date in HQL query
I'm trying to create a new table parsing some of the fields so they can match in some unions I'm using below. For the most part using CAST works just fine, that is for changing formats from string to ...
-1
votes
3
answers
52
views
Getting sql data based on row value
I have a table like so:
date | id
------------------------
2022-04-01 | 1
2022-04-02 | 1
2022-04-03 | 1
2022-04-01 | 2
2022-04-03 | 2
2022-04-02 | 3
I'm trying to get the ...
0
votes
1
answer
38
views
How to write a self join in JPA for MySQL
I have a table called groups with four [relevant] columns; id, parent_id, activated_date and type. parent_id and activated_date are nullable, and a group is considered to be activated if it has an ...
2
votes
1
answer
46
views
Get user data between two date in Hibernate Java
i have an hibernate entity called user.I want to get the list of users who are between two dates a date interval. Example, I have a date D1 and I want to know the people hired between my hiDate and my ...
0
votes
0
answers
20
views
Looping on HQL on a list of elements
I like to know how to use for loop in hql looping on a list (or collection? I am not sure the exact term). My query looks like this:
for item in ('a', 'b') loop (select X, count(*) from Y where Z=item ...
0
votes
2
answers
41
views
HQL, insert two rows if a condition is met
I have the following table called table_persons in Hive:
+--------+------+------------+
| people | type | date |
+--------+------+------------+
| lisa | bot | 19-04-2022 |
| wayne | per | ...