Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 322916

Summary: getParameter on Query throws NPE
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: eclipselink.orm-inbox, guy.pelletier, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed changes none

Description Blaise Doughan CLA 2010-08-17 11:48:06 EDT
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)
Comment 1 Tom Ware CLA 2010-08-17 11:56:49 EDT
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.
Comment 2 Guy Pelletier CLA 2010-11-01 10:30:26 EDT
Created attachment 182141 [details]
Proposed changes
Comment 3 Guy Pelletier CLA 2010-11-01 10:56:23 EDT
Changes have been submitted.

Reviewed by: Gordon Yorke

New test (testQueryGetParameter) added to AdvancedJPAJunitTest
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:31:03 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink