I have two tables (MeasureUnits and TranslationItems) with the following mapping,
which I mapped them like that:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="X.Data.General.Entity.MeasureUnitEntity, X.Data"
table="MeasureUnits">
<id name="Id" column="IdMeasureUnit" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<property name="Code" column="Code" type="string" not-null="true"/>
<set name="MeasureUnitNameTranslationItemSet"
cascade="none"
inverse="false"
lazy="true">
<key column="IdDbRecord"/>
<one-to-many class="X.Data.Translations.Entity.MeasureUnitNameTranslationItemEntity, X.Data"/>
</set>
</class>
</hibernate-mapping>
TranslationItemEntity.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<import class="X.Data.General.Data.MeasureUnitTranslationItemData, X.Data" />
<class name="X.Data.Translations.Entity.TranslationItemEntity, X.Data"
table="TranslationItems"
discriminator-value="0">
<id name="Id" column="IdTranslationItem" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<discriminator column="IdTranslationColumn" type="Int32"></discriminator>
<many-to-one name="Language" column="IdLanguage" not-null="true" outer-join="auto"></many-to-one>
<property name="TranslationName" column="TranslationName" type="string" not-null="true"/>
<property name="IdDbRecord" column="IdDbRecord" type="Int32" not-null="true"/>
<subclass name="X.Data.Translations.Entity.MeasureUnitNameTranslationItemEntity, X.Data" discriminator-value="6"></subclass>
<subclass name="X.Data.Translations.Entity.MatrixNameTranslationItemEntity, X.Data" discriminator-value="2"></subclass>
</class>
</hibernate-mapping>
Then my class MeasureUnitNameTranslationItemEntity just extends TranslationItemEntity.
My HQL, that I am trying to execute is
select new MeasureUnitTranslationItemData(mue.Id, mue.Code, ti.TranslationName)
from MeasureUnitEntity mue left join mue.MeasureUnitNameTranslationItemSet ti
where ti.Language.Id = :InputPrmLanguageId
I expect SQL to be:
select
MeasureUnits.IdMeasureUnit,
MeasureUnits.Code,
ti.TranslationName
from
MeasureUnits
left outer join
(select TranslationItems.* from TranslationItems where IdTranslationColumn = 6) AS ti
on MeasureUnits.IdMeasureUnit=ti.IdDbRecord
where
(ti.IdLanguage=20)
But hql produces:
select MeasureUnits.IdMeasureUnit, MeasureUnits.Code, TranslationItems.TranslationName from MeasureUnits left outer join TranslationItems on MeasureUnits.IdMeasureUnit=TranslationItems.IdDbRecord where (TranslationItems.IdLanguage=20)
Is there a bug, or do you have some special advice about the above mapping and hql?
I would really like to know, why the above hql is not working as I predicted.
Thank you!
Lp
Sebastijan
|