Hi all,
I found an inconsistency and I'd like to know if it's a known bug and if there's a workaround.
I'm using Hibernate 3.6.10.
This is my entity hierarchy:
Profile <= the base entity; it has a "ProfileType" column as a discriminator
Artist <= abstract, extends Profile
SoloArtist <= extends Artist, ProfileType='SA'
BandArtist <= extends Artist, ProfileType='BA'
If I make an HQL query like this:
Code:
select artist from Artist as artist
this gets correctly translated to:
Code:
select artist0_.Id as Id5_, [...] from ProfileTable artist0_ where artist0_.ProfileType in ('SA', 'BA')
It even works for more complex cases like:
Code:
select count(artist) from Artist as artist
or when I have to put conditions on associated tables, like:
Code:
select artist from Artist as artist join artist.user as user where user.active = true
In all of these cases, the "where artist.ProfileType in ('SA', 'BA')" is always correctly generated. So far so good, it was not a so obvious use case!
However, when the abstract entity is put on the right side of a join, Hibernate does not complain, but generates an incomplete SQL. For instance, suppose an artist can write posts:
Code:
select post from Post right join post.publisher as artist where artist.active = true
(please note: the real case is more complex, so the use of the "right join" might sound strange here, but it's just to show my problem; also, don't ask yourself why here I use artist.active and not user, active, it's not important)
What I get in this case is an SQL string like the following:
Code:
select post0_.id as Id5_, [...] from PostTable post0_ right outer join ProfileTable profile_ on post0_.publisherId = profile0_.id where profile0_.active = true
That is, in this case Hibernate does not produce the "where artist.ProfileType in ('SA', 'BA')" that is needed to discriminate between a generic Profile and an Artist.
Is there a reason? A workaround?
Thanks in advance.
Mauro.