Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 363298 - Trying to perform a find operation using the EntityManager and an IdClass containing only one attribute, if this attribute is null, find() operation will fail with a QueryException.
Summary: Trying to perform a find operation using the EntityManager and an IdClass con...
Status: CLOSED WORKSFORME
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P2 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-09 07:46 EST by Mauren Berti CLA
Modified: 2022-06-09 10:25 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mauren Berti CLA 2011-11-09 07:46:09 EST
Build Identifier: 20110615-0604

Error:
javax.faces.FacesException: javax.ejb.EJBException: Exception [EclipseLink-6094] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.QueryException
Exception Description: The parameter name [EMPLOYEE_ID] in the query's selection criteria does not match any parameter name defined in the query.
Query: ReadObjectQuery(name="readObject" referenceClass=TEmployees sql="SELECT EMPLOYEE_ID, EMPLOYEE_NAME FROM T_EMPLOYEES WHERE (EMPLOYEE_ID = ?)")

I noticed the problem occurs ONLY when the IdClass has only one attribute AND it is null. It does not occur when a multiple field IdClass with all fields set to null is provided to the EntityManager.find() method.
I believe this behavior is erroneous, since with earlier EclipseLink versions it did not occur, and with a multiple fields IdClass it also does not occur.

Reproducible: Always

Steps to Reproduce:
1. Create an IdClass containing only one attribute, for an existing database table.
2. Instantiate this IdClass. Don't set any of the attributes of this instance, leaving them null.
3. Perform a EntityManager.find() operation providing this IdClass.
Comment 1 Tom Ware CLA 2011-11-17 14:08:19 EST
What is the expected behavior?  A better error message?
Comment 2 Mauren Berti CLA 2011-11-17 14:20:41 EST
(In reply to comment #1)
> What is the expected behavior?  A better error message?

Actually, it didn't happen with older versions (2.0.2) of EclipseLink. Instead, the query would simply return a null result, like it does when the IdClass has multiple fields and they're all set to null.
Thereby, I think the correct behavior of EntityManager.find() using an instance of an IdClass containing a single field set to null would be a null result instead of throwing an exception, just like it does when I use an IdClass containing multiple fields, all of them set to null.
Comment 3 Tom Ware CLA 2011-11-24 15:27:57 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 4 Mauren Berti CLA 2012-03-09 07:23:51 EST
Will this issue be fixed?
Comment 5 Tom Ware CLA 2012-03-09 08:16:00 EST
Targetting for 2.3.3
Comment 6 Andrei Ilitchev CLA 2012-05-04 12:08:51 EDT
It's not a bug.

By default, if the primary key is mapped to a single field Eclipselink internally uses the "wrapped" value as a primary key - so from IdClass(null) entity manager's find method extracts null - and that's what causing the exception.

User can switch unwrapping of a single field primary key off by explicitly specifying primary key's cache type:

@PrimaryKey(cacheKeyType=CacheKeyType.CACHE_ID)
public class Employee implements java.io.Serializable {...

That would cause find IdClass(null) to return null.
Comment 7 Eclipse Webmaster CLA 2022-06-09 10:16:14 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 8 Eclipse Webmaster CLA 2022-06-09 10:25:27 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink