Questions tagged [hibernate-native-query]

107 questions
2
votes
2 answers

JPA/Hibernate Native Queries not working as per requirement

i am not understanding where the problem lies as the following query is executing as per requirement in MYSQL Workbench. Below is my NativeQuery function in JPA public ConsumerAggregatedDTO getCustomerEnrolled(Long businessAccountId, String…
2
votes
0 answers

PSQL Hibernate Native insert values from a list

I have a table user_services Column | Type | ---------------+---------+ user_id | integer | subservice_id | integer | I have a SortedSet of subservice_ids in Java that I want to insert into my table each with the same user_id.…
uraza
  • 907
  • 4
  • 12
  • 22
2
votes
2 answers

SQL, HQL and Criteria API of hibernate

In which cases we choose SQL, Hibernate Query Language and Criteria API of hibernate?
Z.U.H
  • 325
  • 2
  • 13
2
votes
2 answers

Hibernate DB2 Returns First Charector while using NativeQuery

I am facing the following problem while using Hibernate Native Query to fetch data from DB2 CHAR field. I have a table structure and data as follows. CNTRL_4 COLUMN_ID PARAM ------- --------- -------------------- 1 1 10 …
Partha Sarathi Ghosh
  • 10,936
  • 20
  • 59
  • 84
2
votes
1 answer

Native query executeUpdate seems to commit data in Spring transaction

my usecase is following: When creating an application user (EntityManager.persist) I also have to create a DB user and grant him privileges (that's why I need hibernate nativeQuery). I have a Spring @Transactional method which calls my DAO with both…
aurban
  • 161
  • 4
  • 16
2
votes
1 answer

Hibernate result transformation from SQL view

I created a SQL view, which contains all attributes of User and one more "is_granted", which is boolean value, calculated using custom pl/sql function. In my application I need create native SQL query and map values to the DTO object. Problem is…
Peter Jurkovic
  • 2,686
  • 6
  • 36
  • 55
1
vote
0 answers

Spring data native query filtering by List

Given: Interface projection model with String getType(); Postgres 13; Hibernate+JPA+Spring data; Query filter: " where ... " + " and (COALESCE(:types) is null or model.type in (:types)) " Pageable method in repository contains param …
1
vote
2 answers

Insert native query in spring

I am trying to run an insert native query similar to the following INSERT INTO t3(t1,t2) SELECT t1.c1,sum(t1.c2) table1 t1 WHERE t1.c3 = 'something' GROUP BY t1; I am calling it using a repository and the system actually runs the query without any…
PKS
  • 618
  • 1
  • 7
  • 19
1
vote
1 answer

Why Multiple Where Clause not Woking in nativeQuery

@Query( nativeQuery = true, value = "SELECT td.trip_date, td.trip_code, td.trip_distance, td.trip_travel_time, tu.status, tu.pickup_drop_time, u.id, u.user_name\n" + "FROM trip_details td JOIN trip_users tu ON…
1
vote
2 answers

hibernate native query inserting records in a loop with many-to-one relationship

I'm working on a spring boot project, there I have two tables that are related to each other with OneToMany relationship public class PackGroupEntity{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private…
xarqt
  • 137
  • 1
  • 2
  • 12
1
vote
0 answers

Hibernate parameter to tuple

I try to implement this sort of SQL query in Hibernate native. val list = listOf((z,1),(w,2),(y,3)) SELECT * FROM table WHERE (a, b) IN (:list) to finally obtain something like: SELECT * FROM table WHERE (a, b) IN ((z,1),(w,2),(y,3)) I try…
Jerome Dupont
  • 203
  • 2
  • 7
1
vote
1 answer

how to get Null records from oracle database if column is Number type and nullable

I have Oracle database table with three columns i.e Id,RTOName,VehicleCode. my table looks like below RTOName is the varchar2 type and VehicleCode is NUMBER(2,0) and is nullable field. So I have the data like below and I want to fetch the records…
1
vote
0 answers

ERROR: Column 'id' not found while using NativeQuery in Hibernate 5.4.14

I've following query : try (Session session = sessionFactory.openSession()) { var clients = session.createNativeQuery("select c.fullname, c.city from client c where c.id=:id") .addEntity("c", Client.class) …
Hemlata
  • 367
  • 1
  • 3
  • 13
1
vote
0 answers

Postgresql : null value as query input in java native query throws operator does not exist: character varying = bytea exception

i have a query where i check first if the input parameter(list) is null or i set the condition to pass input parameter in where condition of the query Ex: @Query(value = SELECT * FROM employee t WHERE (((:employeeNameList) is null) or …
1
vote
0 answers

Add elements to an entity list in java or create it from native query hibernate

I have a native hibernate query that returns a list of objects to me, with a for loop I would like to populate a class list, but I do not laugh because the list is always populated by the last element. Where's the error? This the code: ... …
Sergio
  • 138
  • 7