Native query with named parameter fails with Not all named parameters have been set
Named parameters are not supported by JPA in native queries, only for JPQL. You must use positional parameters.
Named parameters follow the rules for identifiers defined in Section 4.4.1. The use of named parameters applies to the Java Persistence query language, and is not defined for native queries. Only positional parameter binding may be portably used for native queries.
So, use this
Query q = em.createNativeQuery("SELECT count(*) FROM mytable where username = ?1");
q.setParameter(1, "test");
While JPA specification doesn't support named parameters in native queries, some JPA implementations (like Hibernate) may support it
Native SQL queries support positional as well as named parameters
However, this couples your application to specific JPA implementation, and thus makes it unportable.
Hibernate QueryException: 'Not all named parameters have been set' - with native query containing ::int
As written in my comment above, I ended up using:
public class LegacyDao extends JdbcDaoSupport
In this way, I was able to reuse the DataSource Hibernate was using.
Not all named parameters have been set: [:int]
try using cast as int
like below in your sql query:
String query= "select max(cast(NULLIF(split_part(num_ordre_decision, '/', 3), '') AS int)) from decision";
Hibernate Exception: Not all named parameters has been set
I see two errors in your sql query:
(1) you have omitted a 'union all' between the first and second line
(2) The first parameter 'dua_num' in the first line is not set
Related Topics
Scheduledexecutorservice Exception Handling
Multiple Axes on the Same Data
Superclass Reference Not Able to Call Subclass Method in Java
Configure Datasource Programmatically in Spring Boot
When Does the Main Thread Stop in Java
Reset Buffer with Bufferedreader in Java
How to Set Same Scale for Domain and Range Axes Jfreechart
Ways to Save Enums in Database
How to Set Base Url for Rest in Spring Boot
How to Fix a Compilation Error for Unhandled Exception on Call to Thread.Sleep()
Try with Resources Introduce Unreachable Bytecode
Best Practice for Passing Many Arguments to Method