Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA and treat keyword(select statement with treat keyword is not the expected one)
JPA and treat keyword [message #1218341] Fri, 29 November 2013 08:16 Go to next message
Emanuele Gesuato is currently offline Emanuele GesuatoFriend
Messages: 12
Registered: December 2012
Junior Member
Hello,

in my scenario I have the following entities structure:
A
|-- B
|-- C
|-- D


B, C and D extends A entity. In B and C I have one attribute "name" and I would like to create a query from A entity but I want to retrieve the attribute "name" if it exists. If it doesn't exist or the attribute has null value, null should be returned.

Using JPQL (with eclipse link 2.5)
SELECT TREAT(a as B).name, TREAT(a as C).name FROM A a


but the SQL generated is this one:
SELECT name, name FROM A WHERE ((DTYPE IN (?)) AND (DTYPE IN (?)))) 


but it is not working because I'm expecting an OR instead of the AND condition.

Am I wrong ? Do am I missing something ?
Is it correct the current behaviour ?

Thanks
Re: JPA and treat keyword [message #1219186 is a reply to message #1218341] Mon, 02 December 2013 14:28 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
This seems to be the correct behavior because what you are asking for does not make sense. If a is an instance of C or D, then Treat(a as B) does not exist and TREAT(a as B).name should be filtered from the result. TREAT is meant to filter based on the subclass. B and C should share a parent that has the name attribute if you really want to make use of it efficiently.

There are a few options though, such as a union of 'select b.name from B' and 'select c.name from C'
Previous Topic:Jersey + EclipseLink: NPE on Tomcat startup
Next Topic:InvalidQuery key [...] exception with CriteriaQuery
Goto Forum:
  


Current Time: Tue Apr 23 15:33:03 GMT 2024

Powered by FUDForum. Page generated in 0.03798 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top