From NHibernate's JIRA: https://nhibernate.jira.com/browse/NH-3057
The mapping:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernate.Test"
namespace="NHibernate.Test.NHSpecificTest.NH3057">
<class name="BaseClass" table="baseclass">
<id name="Id" column="id">
<generator class="assigned" />
</id>
<property name="InheritedProperty" column="inheritedproperty" />
<joined-subclass name="BClass" table="bclass">
<key column="id" />
<many-to-one name="A" column="aid" class="AClass" />
</joined-subclass>
</class>
<class name="AClass" table="aclass">
<id name="Id" column="id" generator="assigned" />
<set name="Bs" inverse="true" lazy="true">
<key column="aid" />
<one-to-many class="BClass" />
</set>
</class>
</hibernate-mapping>
The query:
from AClass a where exists (from a.Bs b where b.InheritedProperty = 'B2')
Generates following sql:
select
aclass0_.id as id2_
from
aclass aclass0_
where
exists (
select
bs1_.id
from
bclass bs1_ – there is missed inner join with base class
where
aclass0_.id=bs1_.aid
and bs1_1_.inheritedproperty='B2'
)
All examples are from NHibernate, but I believe that this bug exists in Hibernate too 'cause I've checked the code and the code is the same. Problem there that subquery from is implied and NHibernate (and Hibernate too) does not generate joins for subclasses in implied from clauses.
|