Questions tagged [nativequery]

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

Related links

355 questions
1
vote
1 answer

Building a bool query with Spring Data Elasticsearch

I'm trying to make a bool must match query in java with this structure GET offers/_search { "query": { "bool": { "must": [ { "match": { "offerLine": "Technology" } } ] } …
1
vote
1 answer

fetching JSON data from a table without model using JPA native query

I have a table something like this TableA : pid | data ac1e |{ "cId":"ac-ga-55" ,"name":"omar","dob":"20/09/1999","age":"23","occupation":"SDE"} ns7f |{ "cId":"as-op-00","name":"raj","dob":"20/06/1999","age":"23","occupation":"SDE II"} I am…
Muhammad
  • 59
  • 9
1
vote
2 answers

Get records which are last updated in n minutes in jpa

I am working on a jpa query which requires to fetch all the records whose last updated time is more than 15 minutes My query goes like Select * from user u where u.last_modified >= NOW() - INTERVAL '5 minutes' I will be passing the minutes…
Thejas
  • 379
  • 5
  • 24
1
vote
1 answer

How to reuse native query code for different tables and views?

I was wondering if this is even possible. If we have situation like this: @Query(nativeQuery = true, value = "SELECT TA.* " + "FROM TABLE_A TA " + "WHERE " + "(LOWER(NAME) LIKE…
nemostyle
  • 794
  • 4
  • 11
  • 32
1
vote
1 answer

How to get SQL Query with parameter values from TypedQuery?

I would like to know if it is possible to retrieve the (Native) SQL Query, with parameter values, from a TypedQuery. The code would be something like: public String getNativeSQLString(){ CriteriaBuilder criteriaBuilder =…
igortorati
  • 23
  • 3
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
1 answer

Error in the native query

Im new to sql and im facing a problem with the below native query public void saveOfflineBatchDetails(BigInteger user_id) { em.createNativeQuery("INSERT INTO rst_offline_transaction_batch (created_date , user_id)" + "VALUES('?1',…
user421607
  • 175
  • 2
  • 4
  • 12
1
vote
2 answers

JPA SqlResultSetMapping to pojo with complex object in attribute

I wonder if it's possible (and if it's the good method) to map sql result of native query in pojo with other pojos in its attributes. I'm searching something like that : ResultPojo Class public class ResultPojo { private MyPojo myPojo; …
Julien
  • 200
  • 1
  • 15
1
vote
1 answer

HOURS[*] syntactical issue 42000-200

I am trying to execute this SQL query SELECT * FROM GY.TABLE_NAME WHERE TEST_ID < 999999999 AND current_timestamp > TEST_GMTS + 20 HOURS When I am expecting it, the response is SQL error 42000, sql state : 42000 Syntax error in SQL statement…
1
vote
0 answers

native query unable to set parameter while creating partition

I have the following query to create a partition, it's working with hardcoded values but is unable to replace parameters dynamically. @Modifying @Query(value = "CREATE TABLE :name PARTITION OF sample_table\n" + "FOR VALUES FROM (a) TO (b)",…
Sachin Sharma
  • 41
  • 2
  • 10
1
vote
1 answer

How to make nested JSON response from a single table

I have a table that contains province, districts and values within a district DATA +------+--------+---------------------+------------+ | ID |Province| District | Codes | +------+--------+---------------------+------------+ | 1001…
arriff
  • 399
  • 1
  • 10
  • 30
1
vote
1 answer

Query in jsonb (JSON array) column with JPA native query

I am using JPA where one of the entity holds user_details (jsonb) column. Below is user_details json array data on which I want to query. [{ "user": "test1", "email": "test1@gmail.com" }, { "user": "test2", "email":…
Sam
  • 79
  • 1
  • 12
1
vote
1 answer

How to pass List of strings as parameter to JPA native query and substitute the same in Postgresql ARRAY[]

I have a JPA native query which looks something like this @Query( value = "SELECT * FROM feature f where jsonb_exists_any(f.feature_json -> 'properties' -> 'ids', array[:ids])", nativeQuery = true) feature_json is a jsonb column and :ids is the…
1
vote
0 answers

How to properly use JPA Inner Self Join query?

Im new to JPA Query and my JPA Self Inner Join on the same table is not working but the SQL query works This is the JPA query Im using SELECT T.codeAuth FROM CodeCm T INNER JOIN Codecm K ON T.langCode = K.langCode where K.code= code1 and K.codeGroup…
1
vote
0 answers

How to map value from native query to entity field that does not exists in db table

I have entity AccountStatus and want to use next native query (I use Spring Data): @Query(value = "SELECT id, code, dscp, 'some address' as address, (SELECT bank_code FROM tbl_bank WHERE id = hdr.BANK_ID) AS CorresBank from account_status",…
Max
  • 21
  • 3