Questions tagged [nativequery]

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

Related links

355 questions
2
votes
1 answer

Native Query INSERT is giving ERROR : Method is only allowed for a Query

I am currently working on a SpringBoot + Hibernate project. I have a requirement to Insert few values to a DB. I am trying to achieve this using Native Query. Below is my Code : @Repository public interface StoreDataRepository extends…
Scarlett John
  • 99
  • 1
  • 11
2
votes
1 answer

Get many object from result of Oracle view

At my Oracle database I have two example tables: tabel A with columns id, a1, a2, a3 tabel B with columns id, b1, b2, b3 I have view for get information from this two tables: CREATE VIEW Foo ("A.id", "A.a1", "A.a2", "A.a3", "B.id", "B.b1",…
kuba44
  • 1,838
  • 9
  • 34
  • 62
2
votes
0 answers

How can I use a resultclass in EntityManager createNativeQuery?

Looking at EntityManager's interface I see there is a signature to create a native query with a result class. /** * Create an instance of Query for executing * a native SQL query. * @param sqlString a native SQL query string *…
benstpierre
  • 32,833
  • 51
  • 177
  • 288
2
votes
1 answer

Doctrine Paginator with NativeQuery

I'm trying to use Doctrine Paginator, but I'm HAVING TO use NativeQuery since I use a custom DB function in my Query. But I get this error: Fatal error: Uncaught Error: Call to undefined method Doctrine\ORM\NativeQuery::getFirstResult() My code so…
David Dutra
  • 391
  • 7
  • 21
2
votes
2 answers

Not able to convert METABASE QUESTIONS to sql query for mongodb

I am using metabase as BI tool for our analytics and my current database is in mongodb. I am able to create questions in metabase but when I try to join collections or try to do some complicated operations then I am not able to do that without…
MAULIK MODI
  • 592
  • 6
  • 10
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
5 answers

How to replace table name with parameter value while using Spring Data JPA nativeQuery

like this: public interface XXXRepository extends CrudRepository { @Query(value = "select * from ?1 where ...", nativeQuery = true) List findByXXX(String tableName, ...);} It gives MYSQL syntax error with upon codes. The syntax…
Jason
  • 303
  • 1
  • 5
  • 13
2
votes
1 answer

Different database, different result type with 'SELECT 1' over jdbc: how to check the value?

I'm working on a project that uses JPA (Hibernate), so almost all the queries are written in JPQL. But for a query I need to get down to the specific database type, so I've written a native query. The project actually is tested with both MySQL and…
watery
  • 5,026
  • 9
  • 52
  • 92
2
votes
1 answer

Complex criteria query: using JPA instead of NativeQuery

I've in my Java EE project this NativeQuery for MySQL: SELECT *, ROUND((price_2-price_1)*100/price_1,2) AS varprice_1, ROUND((quantity_2-quantity_1)*100/quantity_1,2) AS varcant_1, ROUND((price_3-price_2)*100/price_2,2) AS…
moretti.fabio
  • 1,128
  • 13
  • 32
2
votes
2 answers

How do I tell Hibernate to not create a table for this Entity?

I'm using SqlResultSetMapping and the Entity annotations (SqlResultSetMapping requires an Entity with an Id) to tell Hibernate how to populate instances of Foo with native query results data. Non-persisted entity: @SqlResultSetMapping(name =…
Chris Betti
  • 2,721
  • 2
  • 27
  • 36
2
votes
1 answer

Getting generated identifier for JPA native insert query

For performance reasons I need to use some native queries to insert new objects into a database. I have a very sophisticated JPA persistence layer which manages my usual entity reading and writing and I would like to use this persistence layer to…
ali
  • 1,475
  • 4
  • 22
  • 40
2
votes
2 answers

jpa and native queries

I faced with a strange thing with native queries: If I'm trying to use named native query like the following @NamedNativeQuery(name = "native_count_avg_guest_quizzes", resultClass = java.math.BigDecimal.class, query = "select avg(c) as r from…
jjd
  • 2,158
  • 2
  • 18
  • 31
2
votes
0 answers

Is there a way to react to a hibernate native query

I am working on a webapplication with Spring and Hibernate. In a certain situation I want to revoke the user's write access to the database. Therefore I have implemented EventListeners that react to the Events I am interested in. The application…
Landroval
  • 21
  • 2
2
votes
2 answers

Hibernate-generated column aliases break AliasToBeanResultTransformer when using query

What I am trying to achieve is to set a result transformer on a query defined in the following way: String hqlQueryString = "select o.id as id, o.name as objectName from MyObject"; Class resultClass = MyObject.class; Query query =…
Ivaylo Slavov
  • 8,839
  • 12
  • 65
  • 108
1
vote
1 answer

Error with query in java that works under database directly

I have this POSTGRESQL query: select distinct on (a.id) a.id, p.app from application a inner join package p on a.app_id = p.app_id where p.status = 'r' ORDER BY a.app_id, (regexp_matches(p.app_ver, '^(\d+)\.(\d+)\.(\d+)'))[1]::integer DESC, …
Nikola
  • 55
  • 5