Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 346117 - query on isNull(many-to-one mapped attribute) does not work
Summary: query on isNull(many-to-one mapped attribute) does not work
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P2 major with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-17 11:58 EDT by Björn Clemens CLA
Modified: 2022-06-09 10:08 EDT (History)
2 users (show)

See Also:


Attachments
testcase as maven project to reproduce the bug (5.51 KB, application/x-zip-compressed)
2011-05-25 12:09 EDT, Björn Clemens CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Björn Clemens CLA 2011-05-17 11:58:26 EDT
Build Identifier: 2.2.0.v20110202-r8913

environment: optional - many to one-relation between two tables
task: select all elements on many-table what are not mapped to target table (ref_id column contains null value)

the following code returns no result, even if matching values are available in table

CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<AnyMappedObject> criteriaQuery = builder.createQuery(AnyMappedObject.class);
Root<AnyMappedObject> entity_ = criteriaQuery.from(AnyMappedObject.class);
criteriaQuery.where(entity_.get("target").isNull());

TypedQuery<AnyMappedObject> entityQuery = entityManager.createQuery(criteriaQuery);
List<AnyMappedObject> results = entityQuery.getResultList();

Case 1: bidirectional mapping via join-column/inverse-join-column 

generated sql: SELECT t1.ID, t1.anyAttribute FROM TargetTable  t0, SourceTable  t1 WHERE (NOT EXISTS (SELECT t4.ID FROM TargetTable t5, SourceTable t4 WHERE (t5.targetId = t1.ID))  AND ((t0.targetId  = t1.ID) AND (t0.ID = t0.ID)))

expected sql: SELECT t0.anyAttribute FROM AnyMappedObjectTable t0 WHERE  t0.targetId is null

case 2: unidirectional mapping

generated sql: SELECT t1.ID, t1.anyAttribute FROM TargetTable t0, SourceTable t1 WHERE ((t1.targetId IS NULL) AND (t0.ID = t1.targetId))

expected sql: SELECT t1.ID, t1.anyAttribute FROM SourceTable t1 WHERE t1.targetId is null

Reproducible: Always

Steps to Reproduce:
1.see details
Comment 1 Tom Ware CLA 2011-05-20 08:48:11 EDT
Please post examples of the mappings.
Comment 2 Björn Clemens CLA 2011-05-25 12:09:12 EDT
Created attachment 196569 [details]
testcase as maven project to reproduce the bug

added testcase (simple mapping without mapping table ) that reproduces the bug
Comment 3 Tom Ware CLA 2011-05-31 09:41:25 EDT
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 Panu Bloigu CLA 2015-06-12 02:44:05 EDT
I would like to see this fixed as this is a) quite fundamental and b) subtle. 

As a workaround one can use an explicit left join, though, and then call isNull and provide the join as the parameter.
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:08:56 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink