-->
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.  [ 3 posts ] 
Author Message
 Post subject: map an entity class to a stored procedure result set
PostPosted: Fri Jun 03, 2005 11:13 am 
Newbie

Joined: Fri Jun 03, 2005 11:04 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

3.0:

Oracle 9:

I have a stored procedure that calculates values from multiple tables. This procdure returns these values in a reslut set. The result set return does not map to a specific table in the db. can i map this result set to an entity in the mapping file? If im not mapping to a table how can I leave out the class element, id element and just have the sql-query element? is this possible?

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<sql-query name="myOracleStoredProcudure" callable="true">
<return alias="uploadStats" class="com.acme.mypackage.portalhome.UploadStats">
<return-property name="employeeUploaded" column="emp_uploaded"/>
<return-property name="employeeNotUploaded" column="emp_not_uploading"/>
<return-property name="totalClaims" column="total_claims"/>
<return-property name="toatalSupplements" column="total_supplements"/>
<return-property name="busiestDay" column="busiest_day"/>
</return>
{? = call pkg.myOracleStoredProcudure() }
</sql-query>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2005 2:44 pm 
Newbie

Joined: Thu Mar 10, 2005 8:11 pm
Posts: 9
Hi

I have got this to work using the Hiberbate 3.0.5 jar on BEA with oracle, with the latest ojdbc14.jar. Although this may not be the correct way - i tried this and it works. Hopefully somebody from the Hibernate team will evaluate and let us know whether this is the right way.

Stored proc mapping:
Code:
   
<sql-query name="NAME_SP" callable="true">
        <return class="this.is.the.class.Returned">
            <return-property name="field1" column="COLUMN1"/>
            <return-property name="field2" column="COLUMN2"/>
       </return>
        { ? = call SP(
            :para1,
            :para2
        ) }
    </sql-query>


Return class mapping:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
    <class     
        name="this.is.the.class.Returned"
        check=""
    >
            <id name="field1" column="COLUMN1">
               <generator class="assigned" />   
            </id>
            <property name="field2" column="COLUMN2"/>
    </class>
</hibernate-mapping>


Code to access the SP:

Code:
Query query = session.getNamedQuery( NAME_SP );
query.setString( "para1", "someValue1" );
query.setString( "para2", "someValue2" );
List results = query.list();


The return class mapping does not map to a table. The "id" is a concern here since I set a field as id based on intution. Is there a better way to do this?

Thanks,
Amol


Top
 Profile  
 
 Post subject: Re: map an entity class to a stored procedure result set
PostPosted: Thu Oct 22, 2009 12:44 pm 
Newbie

Joined: Thu Oct 22, 2009 12:37 pm
Posts: 3
Hi Amol,

I could like to know what are the values that you give for <property name="field1" column="COLUMN1">
and <return-property name="field1" column="COLUMN1"/>

Since there is no table in the DB.

Thanks,
Sakula


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.