I have a
Person object, mapped as follows:
Code:
<hibernate-mapping>
<class name="com.example.Person" table="persons">
<id name="id" column="id" type="int" />
<property name="fullname" type="string" column="fullname" />
<many-to-one name="birthplace"
class="com.example.Country" column="country_id" />
</class>
</hibernate-mapping>
I know that
session.load(Person.class, personId) will only initialize lazily the
birthplace property: only the
id of the
Country entity is loaded. That makes sense as it exactly corresponds to the single SQL query:
Code:
SELECT id, fullname, country_id FROM persons WHERE id = ?"
Now I have a stored procedure that does some maintenance on the database and returns one line of the
persons table, as in the query above. I would like to map the returned result to a
Person instance, but how do I indicate that the
country_id column maps into the
id field of the
Country entity? (As if it had been lazily initialized by the
load method?)
I am tempted to try this:
Code:
<sql-query name="my_stored_proc_SP" callable="true">
<return alias="p" class="Person">
<return-property name="id" column="id" />
<return-property name="fullname" column="fullname" />
<return-property name="birthplace.id" column="country_id" />
</return>
{ ? = call my_stored_proc() }
</sql-query>
I doubt that's going to work! Any suggestion?