-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem while getting resultset from stored procedure
PostPosted: Mon Nov 05, 2007 5:49 pm 
Beginner
Beginner

Joined: Thu Apr 15, 2004 2:01 pm
Posts: 25
Hello

I have written a stored procedure which returns select from multiple tables. How can I return this resultset to java?

CREATE PROCEDURE [dbo].[spExtract2]
@param1 int,
@param2 varchar(255)
AS
begin
declare @t table(
expense_id VARCHAR(255),
type_name VARCHAR(255),
)

SELECT ex.expense_id, ext.type_name
FROM Expense ex, Expense_Type ext
WHERE ..............
return
end

---------------------------------------------------------------------------

<sql-query name="getExtract" callable="true">
<return class="Extract" alias="ex">
<return-property name="id" column="EXPENSE_ID"/>
<return-property name="type" column="type_name"/>
</return>
{call spExtract(?, :param1, :param2)}
</sql-query>

-------------------------------------------------------------------------------

Return class "Extract" has id and type mentioned. This is just a DTO to put all attributes and not a true entity that can be mapped to any table.

How can I make this query to return list of 'Extract' dtos which can not be really mapped to any table? This dto created just to return resultset.

This is just a sample and I have huge list of attributes in the resultset.

Thanks in advance


Top
 Profile  
 
 Post subject: Calling Stored Procs
PostPosted: Mon Nov 05, 2007 6:10 pm 
Newbie

Joined: Tue Oct 23, 2007 12:14 pm
Posts: 2
HI Gita,

I have been working on a very similar problem this past week and my posting never got a reply :(

I finally got things working this morning so I can share my solution, right or wrong.

I created my query as below with the return mapped to a bean with an associated hbm.xml mapping file. It had the id and property just as your does below. The column name here doesn't refer to any table but rather the named parameters returned in the cursor of your DB Function.


<sql-query name="fraudulentPanCheck_SP" callable="true">
<return alias="fraudulentPanCheck" class="com.fraud.fraudulentpan.FraudulentPanCheckImpl"/>
{? = call abedba.FRAUD_DETECTION_API.check_fraudulentpan(:p_ccnumber) }
</sql-query>

When I actuall invoke the query I recieve a list of the beans I declared.

fraudPanCheckResult = session.getNamedQuery("fraudulentPanCheck_SP")
.setParameter("p_ccnumber",pan)
.list();

if (fraudPanCheckResult.size() > 0) {
return (FraudulentPanCheck)fraudPanCheckResult.get(0);
}

Hope that helps!

-- Grant


Top
 Profile  
 
 Post subject: Unknown entity Extract
PostPosted: Tue Nov 06, 2007 9:19 am 
Beginner
Beginner

Joined: Thu Apr 15, 2004 2:01 pm
Posts: 25
Hello Grant

Thank you very much for your reply.

For me it gives error as unknown entity "Extract". Means I have to create it as a class "Extract" in hbm file but then i don't have equivalent table for the same. Hence this named query gives above mentioned error.

When you mentioned class FraudulentPanCheckImpl in your hbm, did you map that class to any table?

Thanks
gita


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 9:45 am 
Beginner
Beginner

Joined: Thu Apr 15, 2004 2:01 pm
Posts: 25
If I don't mention class in hbm then I get unknown entity error. If I mention class without mapped table as I don't have any then I get following error.

org.hibernate.MappingException: java.lang.StringIndexOutOfBoundsException: String index out of range: 0


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