-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Stored procedure: returns 'id' where entity is expected
PostPosted: Mon Jul 23, 2007 7:28 pm 
Newbie

Joined: Mon Aug 14, 2006 8:06 pm
Posts: 18
Location: Montréal, Québec
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?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 24, 2007 8:13 pm 
Newbie

Joined: Mon Aug 14, 2006 8:06 pm
Posts: 18
Location: Montréal, Québec
I thought about this further, and I have yet to find a satisfactory answer (if there even is one).

For the moment, I have resorted to modifying my stored procedure so that it returns nothing ("void"), and I follow the call to this procedure by a Hibernate reload of the Person instance. That means an extra query to the database, which I would love to do away with if there was a solution to my problem!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.