Questions tagged [hibernate-query]

The Hibernate Query Language

The Hibernate Query Language

Hibernate uses a powerful query language (HQL) that is similar in appearance to SQL. Compared with SQL, however, HQL is fully object-oriented and understands notions like inheritance, polymorphism and association.

Links

  1. Documentation

  2. Tutorial

15 questions
4
votes
1 answer

hibernate jpa projection with @Query

Most of the examples I've seen is using entityManager.createQuery or .createNativeQuery etc. Is there a way to have something like the following working? data class SummaryDto(val employeeName: String, val employerName: String) @Query("select…
Tin Ng
  • 937
  • 2
  • 11
  • 25
2
votes
0 answers

How to convert SELECT ARRAY(column) to Criteria Query

I am using Criteria Query in my project. I have to the following SQL query SELECT ARRAY(column_name) from table I need to write this in Hibernate Criteria query. The current Criteria query code I am using is as follows CriteriaBuilder cb =…
Joker
  • 81
  • 12
1
vote
1 answer

Hibernate queries for combination of column values

I'm designing a schema for products that have multiple variants: @Entity public class Product { @Id @GeneratedValue private long id; @Column(columnDefinition = "JSONB") @Type(JsonType.class) private List
Kevin
  • 1,080
  • 3
  • 15
  • 41
1
vote
0 answers

Replace HQL subquery by a variable

Hi I am trying to convert my SQL query to HQL. The query I am trying to use looks like this select lieu from StorageLocationRef location Where (cast(:disabled as boolean) = true or location.id in (select otherClass.lId from OtherClass…
Wissal
  • 11
  • 2
1
vote
1 answer

Hibernate Search Query for timestamp returns empty list

I am working on a Spring Boot Project with Hibernate and I'm trying to map timestamps out of an SQL-Database. Other queries against strings or numbers work fine, so the problem should not be the project structure itself. Snippet of my User.java…
0
votes
0 answers

HQL query joining three Hibernate entity classes

I have three Hibernate entity classes - Shipment, Parcel and User - mapping respectively tables shipments, parcels and users (see attached db scheme). Parcels represent the "connection point" between a User and a Shipment as each parcel has an…
0
votes
1 answer

How can I fetch parent entity by child class entity value by JPA query?

I am trying to get main parent entity through child entities by the query. My entities looks like below. Main parent entity @Entity @Data @EqualsAndHashCode(callSuper = true) Public class Buyer{ @OneToMany(cascade = CascadeType.ALL,…
Anamika
  • 11
  • 4
0
votes
1 answer

SQL Query to retrieve the value of addScalar value

Query like this : query1 = with codeList (bId, code) as ( select id, listagg(code, ',') ........) select {A.*}, {B.*}, CL.code as codeListName from tableA A left join tableB B on A.id = B.id left join codeList CL on A.id = CL.bId Result of…
Barani r
  • 2,119
  • 1
  • 25
  • 24
0
votes
0 answers

Effective way to add Parameterized query For Hibernate

I have one existing method which is using Hibernate query to fetch the data from DB.Query is created based on IF Else Condition. How to convert the query to a parameterized query. working Code is as : Session session = getCurrentSession(); …
Vipul Singh
  • 393
  • 9
  • 26
0
votes
1 answer

Pagination in Spring using @RestController, but without using Spring Data Rest Pageable?

I know using Spring Data Rest I can use the in-built functionality of Pagination Like this Page findByCategoryId(@RequestParam("id") Long id, Pageable pageable); However, I am in project I am using Spring mvc @RestController and want to…
0
votes
1 answer

Hibernate one-to-many relationship query problem

I can't get result from database when i have one to many relation between two classes. When i write same query for single table(not in relation with any table) then it works fine. Here is my BookType class: @Entity @Table(name="booktype") …
Aca
  • 1
  • 1
0
votes
1 answer

how to use both row num and order by in hibernate sub query?

select e from (select e from table_name e order by e.refid desc) as table_name e where (rownum) between :satrt and :end i get the error as " org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: ( near line 1, column…
0
votes
1 answer

HibernateQuery returns List of Objects instead of Entities

I'm running a query via Hibernate and it´s returning a list. But the list contains objects instead of my Entities... I'm not a pro in Hibernate, but my other queries work well. I have got no idea what is my mistake right now. List…
Hubi
  • 440
  • 1
  • 11
  • 25
0
votes
1 answer

Hiberate search for child entities

I have three classes defined as: 1)Category class:- @Entity @Table(name = "CATEGORY") @Data @NoArgsConstructor @AllArgsConstructor @Indexed public class Category { @Id @GeneratedValue private Long id; @Field(index = Index.YES, store = Store.YES,…
0
votes
1 answer

Identifying if empty list parameter was passed to parameterized @NamedNativeQuery in Spring Boot

I have 3 tables: user, privilege and user_privilege. Last table stores user_id and privilege_id, i.e. information about users and their privileges. I want to filter users by privileges. For this, I am passing list of privilege ID's List