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

Bug 335797

Summary: querying for a Boolean will create a ReportQuery that generates valid SQL but returns no results
Product: z_Archived Reporter: Matthew Denison <matthew.denison>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: NEW --- QA Contact:
Severity: minor    
Priority: P2 CC: adrian.goerler, christopher.delahunt, pawel.zak.pawel, s.merk, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard:
Attachments:
Description Flags
Patch for Bug 335797 - make Boolean instance unique none

Description Matthew Denison CLA 2011-01-30 19:28:18 EST
Build Identifier: EclipseLink, version: Eclipse Persistence Services - 2.2.0.v20101209-r8662

While querying for a boolean value in one of my entities, I was consistently getting NoResultException exceptions when calling getSingleResult(). When manually running the SQL against my database I would get the result I was looking for. I then ran a native SQL query as well as the original query with FINEST logging turned on. It turns out my native SQL was creating a DataReadQuery which would return the boolean I was looking for. The CriteriaQuery would create a ReportQuery which would return no rows.

Reproducible: Always

Steps to Reproduce:
1. Use CriteriaBuilder to query for a single Boolean entity attribute
2. call getSingleResult()
Comment 1 Tom Ware CLA 2011-02-03 10:42:12 EST
Do you get a similar issue when running equivalent JPQL
Comment 2 Matthew Denison CLA 2011-02-03 13:21:35 EST
Hi Tom,

Yes, the same result. JPQL produces another ReportQuery which returns no results. Running the SQL myself that is generated, which is the same SQL the CriteriaBuilder produced, produces a single boolean value so there should be something being returned but no joy.

The boolean column I am querying on is a protected member of a MappedSuperclass. Would this cause any problems that you know of?

At the moment, my workaround is to count the rows returned instead of asking for the boolean value itself. That works.

Thanks!
Comment 3 Tom Ware CLA 2011-02-03 14:57:15 EST
I am not aware of any issue with querying a protected member of a mapped superclass.
Comment 4 Tom Ware CLA 2011-02-10 09:12:16 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 5 Chris Delahunt CLA 2011-02-11 14:27:32 EST
This issue is due to a fix put into TopLink Essentials (glassfish bug 295) to filter out duplicates hen Distinct is used.  Unfortunately, the constant used to indicate a duplicate is ReportyQuery's static RESULT_IGNORED, which is set to Boolean.valueOf(true).  This causes single Boolean values of True to be excluded from the returned results (in ReportyQuery's buildObjects method)

Workaround is to return the entity and then get the boolean value from it directly.
Comment 6 Chris Delahunt CLA 2011-10-26 11:34:34 EDT
*** Bug 348874 has been marked as a duplicate of this bug. ***
Comment 7 Sven Merk CLA 2016-02-15 05:52:40 EST
Created attachment 259759 [details]
Patch for Bug 335797 - make Boolean instance unique
Comment 8 Sven Merk CLA 2016-02-15 06:17:23 EST
Bug 340089 is another duplicate of this bug.

I have attached a fix with minimal side effects to this bug report, perhaps voting with joined forces brings it in:).
Comment 9 Eclipse Webmaster CLA 2022-06-09 10:23:33 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink