Imagine a simple ONE-2-ONE association from Car-->Engine
Car has a scalar property e.g Model ( String )
If the HQL selects:
Select car.Engine, car.Model from Car as car --> returns null for the retreived association i.e Engine ( car.Engine), but correct value for the Model scalar property
This is incorrect expected behaviour, especially if our HQL contains certain fields from an particular Entity( e.g Car) , and also the entire associated entity( e.g Engine).
We are not using lazy-loading ( lazy=false ) and the generated SQL appears to be fine, and is returning results
However, If I modify the HQL to return complete instances Car and Engine i .e
Select car.Engine, car from Car as car -->This works as expected -returns values for both instances Engine and Car
There are JIRA issues that relate to something similar:
HHH-1794 - HQL query (list) that SELECTs instances mixed with scalars returns NULLs (instance mappings are in a one-to-one relation)
HHH-2473 - fetch="join" and property-ref
My mappings for easy reference:
CAR
<hibernate-mapping package="domain"
default-cascade="merge">
<class name="Car" table="OS_CAR">
<id name="Id" column="ID" type="string">
<generator class="uuid"/>
</id>
<property name="Model" type="string" column="MODEL" />
<one-to-one name="Engine" lazy="false" cascade="merge, delete"/>
</class>
</hibernate-mapping>
AND
ENGINE
<hibernate-mapping package="domain"
default-cascade="merge">
<class name="Engine" table="OS_ENGINE">
<id name="Id" column="ID">
<generator class="foreign">
<param name="property">Car</param>
</generator>
</id>
<one-to-one name="Car" constrained="true" lazy="false" foreign-key="FK_CAR_ENGINE"/>
</class>
</hibernate-mapping>
Hibernate version 3.2.3
Database: MySQL
|