My Oracle Support Banner

Setting Parameters Using CreateNativeQuery (Doc ID 389854.1)

Last updated on FEBRUARY 13, 2024

Applies to:

Oracle Containers for J2EE - Version and later
Information in this document applies to any platform.


The @NamedQuery annotation defines EJB-QL queries for which the :param syntax is valid.
I wanted to use the @NamedNativeQuery (not @NamedQuery) annotation to define native SQL and not
use EJB-QL. Therefore, I tried the same syntax with @NamedNativeQuery, but it did not work.
the following code was used:

public List<Employee> findByName(String name) {
Query queryEmpByName = em.createNativeQuery("select empno, ename, sal,
hire_date from emp where upper(ename) like upper(?1)");
queryEmpByName.setParameter(1, name);
return queryEmpByName.getResultList();

and now a NullPointerException is generated.

How to use the param syntax with NamedNativeQuery?


To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!

In this Document

My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.