-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: JPA 2.1 TREAT generates inner join
PostPosted: Wed Jun 25, 2014 12:17 pm 
Newbie

Joined: Wed Jun 25, 2014 11:33 am
Posts: 1
I have a question regarding how the new TREAT downcasting is handled.

Currently we have the following models using JOINED inheritance.

AbstractBase { String value0; }
Child0 extends AbstractBase { String value1; }
Child1 extends AbstractBase { String value2; }

Now using the Criteria API (cb.treat(Root<X>, Class<T>)) we generate the following HQL:

select generatedAlias0.id, generatedAlias0.value0, treat(generatedAlias0 as Child0).value1
from AbstractBase as generatedAlias0


Now this gets translated to SQL as follows:

select abstractba0_.id as col_0_0_, abstractba0_.VALUE_0 as col_3_0_, abstractba0_1_.VALUE_1 as col_4_0_
from PCY_T_ABSTRACT_BASE abstractba0_
inner join PCY_T_CHILD_0 abstractba0_1_ on abstractba0_.id=abstractba0_1_.id
left outer join PCY_T_CHILD_1 abstractba0_2_ on abstractba0_.id=abstractba0_2_.id


For a JOINED-Inheritance setup it would seem that a LEFT JOIN is more appropriate here instead of the INNER JOIN used to pull in the CHILD_0 table.

Now my question is, is there anyway to force the joining of CHILD_0 to use a LEFT OUTER JOIN? From the JPA 2.1 API there appears to be no possibility of passing in a JoinedType value, but perhaps, there is a Hibernate-specific method which could be used instead?

Thanks,
Tito


Top
 Profile  
 
 Post subject: Re: JPA 2.1 TREAT generates inner join
PostPosted: Wed Jun 10, 2015 9:30 pm 
Newbie

Joined: Tue Jul 07, 2009 11:18 am
Posts: 5
Location: Newton, MA
Anybody has a solution for this? I noticed that Hibernate normally fetches polymorphic queries using a left outer join, but the moment you use "treat" it switches to an inner join. It seems to me that with this behavior Hibernate's "treat" implementation is useless for tables with joined inheritance.

In my case, I'm stuck with the Criteria API, which has even fewer options for working around the problem. At least with JPQL under JPA 2.1 you can join with arbitrary tables, so in theory you could left join the base class table with the table(s) representing the subclasses. Not so with the Criteria API.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.