Questions tagged [nativequery]

JPA concept that allows queries in your native database syntax (instead of JPQL)

Related links

355 questions
60
votes
13 answers

JPA passing list to IN clause in named native query

I know I can pass a list to named query in JPA, but how about NamedNativeQuery? I have tried many ways but still can't just pass the list to a NamedNativeQuery. Anyone know how to pass a list to the in clause in NamedNativeQuery? Thank you very…
Li Ho Yin
  • 1,008
  • 2
  • 10
  • 15
38
votes
5 answers

How to truncate a table using Doctrine 2?

I assume that I need to build a native query to truncate a table using Doctine2. $emptyRsm = new \Doctrine\ORM\Query\ResultSetMapping(); $sql = 'TRUNCATE TABLE Article'; $query = em()->createNativeQuery($sql, $emptyRsm); $query->execute(); This…
murze
  • 4,015
  • 8
  • 43
  • 70
25
votes
2 answers

Spring Data JPA delete native query throwing exception

I have a User entity and a Role entity. The relationship is defined like this: @OneToMany @JoinTable(name="USER_ROLES", inverseJoinColumns=@JoinColumn(name="ROLE_ID")) private List roles = null; Now, when I delete a role, I need to delete…
dnc253
  • 39,967
  • 41
  • 141
  • 157
24
votes
7 answers

How can I use MySQL assign operator(:=) in hibernate native query?

I'm using Hibernate. I wrote some native query because I need to use sub select statement. Query looks like this: SELECT sub.rownum FROM (SELECT k.`news_master_id` AS id, @row := @row + 1 AS rownum FROM keyword_news_list k …
Sanghyun Lee
  • 21,644
  • 19
  • 100
  • 126
19
votes
4 answers

JPA Data Repositories with SqlResultSetMapping and native queries

I was stuck with the following situation: My entities are related to each other, but in such a way that i could not use JPQL. I was forced to use native SQL. Now I want to map these results to a ValueObject. To be clear, I don't want to get a list…
LeoRado
  • 331
  • 1
  • 3
  • 10
12
votes
4 answers

Set list parameter to native query

I would like to set parameter to a native query, javax.persistence.EntityManager.createNativeQuery Something like that Query query = em.createNativeQuery("SELECT * FROM TABLE_A a WHERE a.name IN ?"); List paramList = new…
Silence
  • 291
  • 2
  • 3
  • 13
11
votes
2 answers

spring data jpa - Custom type conversion in interface-based projection

I'm trying to implement Interface-based Projection but I cannot make it work with my custom type column. Below example of what I'm trying to do: Repository: @Query(value = "SELECT customType from TABLE", nativeQuery = true) List
10
votes
2 answers

How to use @ConstructorResult annotation

I have some native query and want to map the result of query execution into List of NON-Entity POJO classes: @SqlResultSetMapping( name = "SomeMapping", classes = { @ConstructorResult(targetClass = SomeClass.class, …
Silence
  • 291
  • 2
  • 3
  • 13
9
votes
1 answer

How to map ONE-TO-MANY native query result into a POJO class using @SqlResultSetMapping

Im working in a backend API using Java and MySql, and I'm trying to use @SqlResultSetMapping in JPA 2.1 for mapping a ONE-TO-MANY native query result into a POJO class, this is the native query: @NamedNativeQuery(name = "User.getAll”, query =…
Tamer Saleh
  • 473
  • 9
  • 21
8
votes
4 answers

Hibernate native query with multiple joins on same table returning wrong results

I am using a native sql query where I have a players table to which I join three times, first to get the batsman name, then to get bowler name and then to get the fielder name. Now the first join works, but the next two also return the same name i.e…
Khizar
  • 2,288
  • 5
  • 32
  • 53
7
votes
1 answer

Cannot use Tuple class with native queries

I'm using Spring Boot 1.5.13.RELEASE and I'm trying to use the javax.persistence.Tuple to receive the results from a native query, like: Query q = em.createNativeQuery(QUERY_STRING, Tuple.class); q.setParameter(1, param1); q.getResultList(); But I…
Dherik
  • 17,757
  • 11
  • 115
  • 164
7
votes
5 answers

How to get multiple columns from table using JPA?

For example I have a table as Student it's contain columns like id, name, age I am reverting particular column values by using NativeQuery like below. Query query = entityManager.createNativeQuery("SELECT age FROM Student"); List…
Prabha
  • 707
  • 2
  • 11
  • 27
7
votes
1 answer

Conversion of java object to Date or DateTime

I have a query of inner join tables: List resultList = entityManager.createNativeQuery(SOME QUERY).getResultList(); When i try to access the elements of Object[] one of which is a Date I tried doing this: for(Object[] obj : resultList) { …
tinker_fairy
  • 1,323
  • 1
  • 15
  • 18
5
votes
2 answers

How to resolve No converter found capable of converting from type TupleBackedMap to type [com.example.dto.ExampleDto]

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [com.example.dto.ExampleDto] at…
Roe hit
  • 457
  • 1
  • 7
  • 23
5
votes
5 answers

Spring jpa native query sorting adding prefix to order by field name

I have problem with sorting. Repository method: @Query(nativeQuery = true, value = "SELECT D.ID as dealerId , D.NAME as dealerName, K.ID as kpiId, " + "K.NAME as kpiName FROM REGION R, DEALER D, KPI K " + "WHERE R.IMPORTER_ID =…
Pavel Konir
  • 51
  • 1
  • 3
1
2 3
23 24