Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322916 - getParameter on Query throws NPE
Summary: getParameter on Query throws NPE
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-17 11:48 EDT by Blaise Doughan CLA
Modified: 2022-06-09 10:31 EDT (History)
3 users (show)

See Also:


Attachments
Proposed changes (7.23 KB, patch)
2010-11-01 10:30 EDT, Guy Pelletier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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