Community
Participate
Working Groups
For the query: @NamedQuery(name = "findCustomerByName", query = "SELECT c " + "FROM Customer c " + "WHERE c.firstName = :firstName AND " + " c.lastName = :lastName") When I try to introspect the parameter types: Query namedQuery = entityManager.createNamedQuery(findCustomerByName); namedQuery.getParameter("firstName").getParameterType(); Then I get the following NPE: java.lang.NullPointerException at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getParameter(EJBQueryImpl.java:1327) at org.example.common.JPAResource.namedQuerySingleResult(JPAResource.java:52) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597)
The following test can be added to our test environment to see the problem: public void testParam(){ EntityManager em = createEntityManager(); Query query = em.createQuery("select e from Employee e where e.salary = :sal").setParameter("sal", "1000"); Set params = query.getParameters(); Parameter param = query.getParameter("sal"); query.getResultList(); } Stepping into query.getParameter("sal") will show you that for some reason that although the Map or parameters contains a Parameter that should be hashed with "sal".hashCode(), for some reason that paramater is not returned by get("sal"). Apparently something is not working as expected with either our implementation of hashCode() or equals() on our Parameter Implementation.
Created attachment 182141 [details] Proposed changes
Changes have been submitted. Reviewed by: Gordon Yorke New test (testQueryGetParameter) added to AdvancedJPAJunitTest
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink