-->
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: How to call Stored Procedure in Hibernate
PostPosted: Mon Apr 21, 2008 1:08 pm 
Newbie

Joined: Mon Apr 21, 2008 1:03 pm
Posts: 2
Hi I am using Hibernate with JSP.

I m having stored procedure in Oracle.

How to call this SP in JSP using Hibernate?

Regards.


Top
 Profile  
 
 Post subject: Try this
PostPosted: Mon Apr 21, 2008 7:43 pm 
Beginner
Beginner

Joined: Thu Feb 28, 2008 11:53 am
Posts: 23
In your hibernate config file enter this:

Code:
<sql-query name="some_name" callable="true">
<return alias="u" class="class_name">
<return property name="id" column="user_id"/>
...
</return>
{call  procedure_name(?,:bind_parameter)}
</sql-query>


If the class_name's properties are the same as their column names then you can leave the <return property="" column="" />s out like this
Code:
<sql-query name="some_name" callable="true">
<return alias="some_alias" class="class_name">
{call  procedure_name(?,:bind_parameter)}
</sql-query>


? is your output parameter from the sproc and then you have you bind parameter that you pass in (you can also use positional ?)

You call the sproc in your servlet like this

Code:
Query q = session.getNamedQuery("some_name");
q.setParameter("bind_parameter","string or number");
List result = q.list();

[/code]


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.