Reputation: 20633
Lets supose that I have 3 abstract super classes: SuperA
, SuperB
and SuperC
.
Lets supose that each of theses super classes had a lot of more specific implementations, and all the superclasses are annotated with @Inheritance(strategy = InheritanceType.JOINED)
.
More specific:
Aa
<- SuperA
and has a List of SuperB
(the bbs
property); Bb
<- SuperB
and has a List of SuperC
(the ccs
property); Cc
<- SuperC
and has a foo
property. Then, when I try a query like the following, I got an error saying that it could not find the property foo
in the type SuperC
. Bb
has a list of the abstract type, and I can't change that. So, I do not know how to make the query works.
select a from Aa a left outer join a.bbs b where b.ccs.foo = :foo
Any tip will help. Thanks in advance.
Edit:
BTW: the exception:
org.hibernate.exception.SQLGrammarException: Unknown column 'cc3_1_.foo' in 'where clause'
Edit 2:
I look for JPA docs, and found something that could work, if I'm not using Hibernate.
Edit 3:
I change it to use two SQL's. First, I find the id of the C based on the foo
property, then I just do the query comparing with the id.
The problem here, is that I have to do 2 SQL's for every time I want this... but, at least it works.
Upvotes: 2
Views: 1136
Reputation: 873
You need one more join for the list of Cc's then it should be fine:
select a from Aa a left outer join a.bbs b join b.ccs c where c.foo = :foo
as ccs is a list you can't "dereference" it's property this way, if you could you wouldn't need joins, you could simply write: a.bbs.ccs.foo
but this is not the case so you need to join the lists as I wrote above.
Upvotes: 2