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

Bug 329092

Summary: WIKI: example: case difference for named parameter in query and setParameter() will insert null as value
Product: z_Archived Reporter: Michael OBrien <michael.f.obrien>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: NEW --- QA Contact:
Severity: minor    
Priority: P3 CC: eclipselink.documentation-inbox
Version: unspecifiedFlags: michael.f.obrien: documentation+
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
URL: http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_Named_Parameters_in_a_Native_Query
Whiteboard:
Bug Depends on:    
Bug Blocks: 329093    

Description Michael OBrien CLA 2010-10-29 15:09:46 EDT
>The case is wrong in the following example
>The code as written will insert [NULL] as a value for the firstname named parameter

http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_Named_Parameters_in_a_Native_Query

>following 
Query queryEmployees = entityManager.createNativeQuery(
    "SELECT * FROM EMPLOYEE emp WHERE emp.fname LIKE #firstname");
queryEmployees.setParameter("firstName", "Joan");
Collection employees = queryEmployees.getResultList();

>should be
Query queryEmployees = entityManager.createNativeQuery(
    "SELECT * FROM EMPLOYEE emp WHERE emp.fname LIKE #firstname");
queryEmployees.setParameter("firstname", "Joan");
Collection employees = queryEmployees.getResultList();

>non-trivial as the wiki documentation needs to be modified to either set the correct capitalization
>or set the upper case flag [useUpperCaseForComparisions] on the parameter


>The following bind parameter call will fail when the cases do not match for
aQuery = entityManager.createNativeQuery("select * from table where id = #anid....");
aQuery.setParameter("anId", 32); // force use of "anId" instead of "anid" to test case-sensitivity

>in the following [value] will be null
DatasourceCall.translateQueryString():739
  Object value = getValueForInParameter(parameter, translationRow, modifyRow, session, false);

org.eclipse.persistence.example.dataparallel.GridClient at localhost:52520	
	Thread [Main Thread] (Suspended)	
		SQLCall(DatasourceCall).translateQueryString(AbstractRecord, AbstractRecord, AbstractSession) line: 739	
		SQLCall(DatabaseCall).translate(AbstractRecord, AbstractRecord, AbstractSession) line: 985	
		CallQueryMechanism(DatasourceCallQueryMechanism).executeCall(DatasourceCall) line: 205	
		CallQueryMechanism(DatasourceCallQueryMechanism).executeCall() line: 192	
		CallQueryMechanism(DatasourceCallQueryMechanism).executeNoSelectCall() line: 235	
		CallQueryMechanism(DatasourceCallQueryMechanism).executeNoSelect() line: 215	
		DataModifyQuery.executeDatabaseQuery() line: 85	
		DataModifyQuery(DatabaseQuery).execute(AbstractSession, AbstractRecord) line: 782	
		DataModifyQuery(DatabaseQuery).executeInUnitOfWork(UnitOfWorkImpl, AbstractRecord) line: 685	
		RepeatableWriteUnitOfWork(UnitOfWorkImpl).internalExecuteQuery(DatabaseQuery, AbstractRecord) line: 2960	
		RepeatableWriteUnitOfWork(AbstractSession).executeQuery(DatabaseQuery, AbstractRecord, int) line: 1303	
		RepeatableWriteUnitOfWork(AbstractSession).executeQuery(DatabaseQuery, AbstractRecord) line: 1285	
		RepeatableWriteUnitOfWork(AbstractSession).executeQuery(DatabaseQuery, List) line: 1259	
		EJBQueryImpl<X>.executeUpdate() line: 534	
		GridClient.nativeQuery() line: 119	
		GridClient.main(String[]) line: 353	

>The case must be the same for both the named SQL query parameter name and the setParameter("name", value) call
>this works
            aQuery.setParameter("anid", 32);

>trace
parameter	DatabaseField  (id=155)	
	name	"anid" (id=154)	
	nameForComparisons	null	
	qualifiedName	"anid" (id=154)	

	useUpperCaseForComparisons	false	
value	Integer  (id=106)	
	value	32
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:25:06 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink