Multiple TREAT operators does not work properly for joined inheritance


I use joined inheritance mapping for my tables, and found to my dismay that
using the JPA 2.1 "treat" construct to downcast causes the usual left outer
join to a subclass table to become an inner join. This makes the construct
useless since the inner join makes polymorphic queries impossible: only the
treat-ed type will be retrieved. In the case where 2 or more downcasts are
made, absolutely no records can be retrieved.

Sample JPA 2.1 code:

CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Object[]> query = cb.createQuery(Object[].class);
Root<Pet> root = query.from(Pet.class);
cb.treat(root, Cat.class).get("felineProperty"),
cb.treat(root, Dog.class).get("canineProperty")

The resulting SQL looks like (mocked up):

Pet pet0_
left outer join
Bunny bunny0_
on pet0_.ID=bunny0_.ID
inner join
Cat cat0_
on pet0_.ID=cat0_.ID
inner join
Dog dog0_
on pet0_.ID=dog0_.ID




Alessandro Moscatelli
February 27, 2018, 10:17 PM

I would not expect nothing more of a "retort" after such an issue is ignored for 3 years if I were you.
But probably my point of view is wrong as I am just the ugly guy who is not going to contribute and is just going to try and use another jpa provider.

From my point of view opening an issue is already a form of contribution, and ignoring such contribution is ... well ... just wrong.

I have my own projects/frameworks/duties and fixing hibernate is not among them.

Covering your head with sand have lower probability in making Hibernate better than my retorts.

Guillaume Smet
February 27, 2018, 10:28 PM

In any case, your attitude, starting with your very first message, is really a nice way to contribute.

Thanks a lot for that. It helps a lot.

Now I think we will all get back to work .

Christian Beikov
February 27, 2018, 10:45 PM

Your contribution, or actually the one of cwong15 is not ignored, it is acknowledged and being worked on. It's just not so easy to get done right, but good luck with "other" jpa providers.
EclipseLink has IMO much more severe bugs and some are actually ignored for already 7 years or more. The only other (JPA 2.1ish) provider is DataNucleus which isn't certified and probably lacks a few things also. OpenJPA is only JPA 2.0 certified and hasn't seen much development lately.
It's ok if you don't contribute code, but you are in no position to demand a fix immediately. Many people that work on Hibernate do this in their spare time. In fact we have our own priorities just like you, and apparently this isn't such a big priority to anyone.

Are you fixing bugs in your projects for "free"? Good for you, we would very much appreciate if you could take the time for Hibernate as well.
Or do you charge your customers? Then please understand that we have customers of our own that pay our salaries which entitels them to actually "demand" something. If you find somebody to do it for "free"(maybe you could do it yourself?) or pay someone to do it, this fix will probably be merged in no time!

We are going to fix this eventually, but it would be a lot easier if you actually helped rather than just demand it being done faster.

Alessandro Moscatelli
December 17, 2018, 6:38 PM

You are welcome. I am always happy to contribute.
Just to be clear : I was not, and I am not, demanding anything. But you clearly you didn't understand what I meant.
I simply expressed an objective statement or evaluation on the state of this provider.

Oh, another year is passed by, in case somebody didn't notice.
I was just removing old bug references from my favorites and I found out about your clever replies.

Wish you luck with fixing this 'eventually'.

Nelson Manuel Tam Urribarri
January 17, 2020, 11:29 AM


I can confirm that this bug still exist in version 5.4.10.Final

any news about this?







Fix versions





Suitable for new contributors


Requires Release Note


Pull Request





Affects versions