question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parameters do not work on NativeQuery

See original GitHub issue

When I run this code:

String cql = "SELECT ids FROM something WHERE value = ?1";
Query q = entityManager.createNativeQuery(cql, MyClass.class);
q.setParameter(1, value);

it throws an exception:

com.impetus.kundera.query.QueryHandlerException: No named parameter present for query
    at com.impetus.kundera.query.KunderaQuery.setParameterValue(KunderaQuery.java:755)
    at com.impetus.kundera.query.KunderaQuery.setParameter(KunderaQuery.java:718)
    at com.impetus.kundera.query.QueryImpl.setParameter(QueryImpl.java:473)

looking a the Kundera code (QueryResolver.java), it doesn’t support parameters for NativeQueries. The list of valid parameters it built up initFilter(), which is called from postParsingInit(). However, postParsingInit is not called if the query is native:

if (!isNative)
{
...
        parser.parse();
        kunderaQuery.postParsingInit();
...
}

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
canopenerdacommented, Mar 1, 2016

@mevivs

Since setParameter is not supported on native queries (includes named native queries), what is the suggested way to execute parameterized native queries except constructing the query with parameter and value in entirety?

Thank you!

Regards, Malcolm

0reactions
AntonYudincommented, Jan 26, 2018

+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Native query with named parameter fails with "Not all ...
Named parameters are not supported by JPA in native queries, only for JPQL. You must use positional parameters. Named parameters follow the rules...
Read more >
JPA Query Parameters Usage - Baeldung
We may use either positional or named parameters, but we must not mix them within the same query. 4.1. Positional Parameters.
Read more >
Spring Data JPA Native Query - Named parameters are not ...
[Solved]-Spring Data JPA Native Query - Named parameters are not being registered-Springboot ... The single quotes around your parameters is probably the issue....
Read more >
JPA Native Query example with Spring Boot - BezKoder
In this tutorial, you will know how to use Spring Data JPA Native Query example (with parameters) in Spring Boot. I will show...
Read more >
Parameters are not passed to proxied native Query instance ...
I try to migrate from Spring Data JPA 1.11.10 to Spring Data JPA 2.x. ... When doing so all native queries won't work...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found