Invalid SQL generated for mapping with property-ref

Description

Consider mappings:
<class name="MedDRATerm" table="MBROW_MEDDRA_TERMS" mutable="false"
batch-size="50">
<cache usage="read-only" region="dictionary" />
<id name="medDRATermId" type="long" column="TERM_ID">
<generator class="assigned" />
</id>
<map name="termNames" table="MBROW_TERM_NAMES" lazy="true"
batch-size="50">
<cache usage="read-only" region="dictionary" />
<key column="MEDDRA_CODE" property-ref="medDRACode" />
<index column="LANGUAGE_ID"
type="com.roche.dss.meddra.dao.type.LanguageType" />
<element column="NAME" type="string" />
</map>
<property name="medDRACode" column="MEDDRA_CODE"
type="com.roche.dss.meddra.dao.type.MedDRACodeType" />
</class>
<class name="MedDRATermInstance" table="MBROW_MEDDRA_TREES"
mutable="false">
<cache usage="read-only" region="dictionary" />
<id name="medDRATermInstanceId" type="long" column="NODE_ID">
<generator class="assigned" />
</id>
<many-to-one name="medDRATerm" class="MedDRATerm"
column="TERM_ID" fetch="join" not-null="true" insert="false"
update="false" />
</class>

and a HQL query:

from MedDRATermInstance i where i.medDRATermInstanceId is not null and i.medDRATerm.termNames[1] like 'headache'

Having this Hibernate will generate following SQL:

SELECT ...
FROM orcl_gthes.mbrow_meddra_trees meddraterm0_,
orcl_gthes.mbrow_term_names termnames2_
WHERE meddraterm1_.meddra_code = termnames2_.meddra_code
AND termnames2_.language_id = 1
AND meddraterm0_.term_id = meddraterm1_.term_id
AND (termnames2_.NAME LIKE 'headache')

Please note that WHERE clause refers to alias meddraterm1_ which is not mentioned in FROM section!!!!

Environment

Oracle 8.1.7

Status

Assignee

Steve Ebersole

Reporter

JakubJ

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

3.1.3

Priority

Minor