Questions tagged [hibernate-native-query]

107 questions
0
votes
1 answer

Query based on map index in spring data jpa native query

I have two entities AAA and BBB as follows class AAA{ @Id private String Id; @OneToMany(mappedBy = "aaa", fetch = FetchType.EAGER, cascade = CascadeType.ALL) @MapKey(name = "bbbType") @Setter private Map bbbDetails; …
0
votes
0 answers

Native query with named parameter in "LIKE"

I want to use named parameters in native query. It works fine in cases like this: and p.department_id in :myDepthsIds ... query.setParameter("myDepthsIds", myDepthsIds); However, I want to use named parameter in "LIKE" part of query, and if I…
MichaelSun
  • 90
  • 1
  • 9
0
votes
0 answers

Convert plain list from SQL Query result into a nested list

I've got a List as the result of a select query, using NativeQuery and Java 8. Then I need to create to convert this plain list into a nested object list. This would be an example: --List from select-- { "result":[ { "name":…
Rachel
  • 65
  • 11
0
votes
1 answer

Bulk update using EntityManager / Hibernate

I am using Hibernate and have (as an example) an Employee entity with 10000 entries. Let's assume 1000 of them have a salary of 4000 which I want to increase to 5000. I have difficulties to find an effective way to do this. Doing it in code by…
mgerbracht
  • 87
  • 7
0
votes
1 answer

cant using "LIKE" in native query spring boot

I try to get orders of user by query : @Query(value = "SELECT * FROM ORDERS WHERE USER_ID = ?1 AND CAST(CREATE_AT AS NVARCHAR(100)) LIKE ?2 OR CAST(GRAND_TOTAL AS NVARCHAR(100)) LIKE ?2 OR CAST(STATUS AS NVARCHAR(100)) LIKE ?2" , nativeQuery =…
0
votes
1 answer

How to fetch single record string value using hibernate native query?

StudentModel studentModel; String sql = "SELECT name from table; Query query = sessionFactory.getCurrentSession().createSQLQuery(sql) .setResultTransformer(Transformers.aliasToBean(StudentModel.class)); studentModel= (StudentModel)…
UJJAWAL KUMAR
  • 31
  • 1
  • 6
0
votes
0 answers

SQL syntax error while trying to execute script with multiple CREATE VIEW statements via EntityManager

I would like to create a bunch of SQL views at my Quarkus application startup and I wrote @Inject EntityManager em; public void exec(... sql) { logger.info("EXECUTING " ...); sql = "BEGIN\n" + sql + "\nEND"; Query q =…
Dims
  • 47,675
  • 117
  • 331
  • 600
0
votes
2 answers

How to update column in JPA native query which annothed with @Lob

I have an entity class and repository. Here I'm trying to execute update query but not working. How to update Lob column in native query or any another solution on jpa query to update Lob column. @Entity @Table(name = "comment") public class…
Priya
  • 3
  • 6
0
votes
1 answer

org.hibernate.exception.SQLGrammarException: Conversion failed when converting the nvarchar value 'ViewWebApp' to data type int

I am trying to use the NativeQuery feature in Hibernate with JOIN and subqueries in SQL query, when I am passing the list of parameters with IN condition it's not working. Code: Query query1 = entityManager.createNativeQuery("select product0_.* from…
0
votes
0 answers

Java createNativeQuery: How to set parameter as an option?

I have an use-case where passing parameters is optional. Can this be somehow achieved as if I try to set parameter (Using keyName or position) and if the key or position is absent in main query it returns IllegalParameterException. This is useful if…
Jake
  • 391
  • 1
  • 4
  • 22
0
votes
0 answers

how to get queries from jpa-named-queries.properties

I'm using jpa-named-queries.properties file for writing HQL and native queries for my repository interfaces. now the problem here is when i write native query, returned values i cant directly cast into Entity as column defined as Long in entity are…
0
votes
0 answers

How to bulk delete in Spring Hibernate?

Using Spring Boot + Hibernate, I'm trying to bulk delete data using a nameQuery or nativeQuery. A few elements have constraint violations and Spring/Hibernate generates an entire rollback. Is it possible to avoid the rollback? i.e. 100 records for…
0
votes
0 answers

Exception : com.microsoft.sqlserver.jdbc.SQLServerException: invalid column name id

when I ty to run this query @Query(value = "select TOP(10) noleggi.id_libro, count(*) as occ from noleggi " + "group by noleggi.id_libro " + "order by occ desc", nativeQuery=true) List
Max
  • 41
  • 2
  • 7
0
votes
0 answers

JPQL Native Query result couldn't be mapped to List?

I have a problem with my Query, when the query executes in intellij console with my parameters it works fine and gives output: CAR EARNINGS 5 140 6 100 And that's fine but I need to create a new list of object and send it back to my frontend in…
0
votes
0 answers

Hibernate Native Query Left Join vs Postgresql Left join (Why are they different)

I'd like to start by saying that I'd like to think I am pretty proficient sql (10 years of experience) and have ran into a head scratcher. I have the following data Group Id Name 1 Group 1 2 Group 2 User Id Name 1 Jon Williams 2 Mike…
RiceRiceBaby
  • 1,546
  • 4
  • 16
  • 30