HI all,
I'm encountering a problem where I'm trying to get the numer of results a query will return (via count) but I'm not really managing to state this correctly in Hibernate.
The class layout is as follows (I've tried to simplify it a bit to make the basic problem clear):
There's a class BaseClass, it has the annotation
Code:
@Inheritance(strategy=JOINED)
on it. There's another class SubClass, that extends this BaseClass.
There's also a (Base)Reference class that associates members of BaseClass with a value class called Lit. The Reference class is also polymorphic, hence the entry_id and entry_type values below. The query I'm using is:
Code:
select
distinct ref.base from Reference as ref
where
ref.lit=:lit and ref.base.class = SubClass
leading to the query:
Code:
select distinct base_.id as base1_13_,
base_.experiment_date as base2_13_,
base_1_.date_created as date2_36_,
base_1_.description as descript3_36_,
case
when base_1_.id is not null then 1
when base_.id is not null then 0
end as clazz_
from
references base0_
inner join
base base_
on base0_.entry_id=base_.id
left outer join
sub base_1_
on base_.id=base_1_.id
where
base0_.entry_type='BASE'
and base0_.lit_id=?
and case
when base_1_.id is not null then 1
when base_.id is not null then 0
end=1
So I try to get the count with:
Code:
select
count(distinct ref.base) from Reference as ref
where
ref.lit=:lit and ref.base.class = SubClass
which gives us the query:
Code:
select
count(distinct base0_.entry_id) as col_0_0_
from
references base0_,
base base_
where
base0_.entry_type='BASE'
and base_.entry_id=base1_.id
and base0_.lit_id=?
and case
when base_1_.id is not null then 1
when base_.id is not null then 0
end=1
Which fails because base_1_ was never declared. Any idea what's going wrong here and how to fix it?
edit: I'm using hibernate 3.2.6