You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by GEDA <ge...@gmail.com> on 2007/09/12 14:50:14 UTC

Call Oracle stored function using Hibernate

Hi. I am using Spring, Struts 2, Hibernate and Oracle as DB. Until now
everything worked ok since I only needed full entity objects but now I have
to call some stored functions from the DB using the hibernate api. Until now
I have used the following syntax: Query q =
getEntityManager().createQuery(). 

Can you give me an example please on how to call a stored function ?

Thank you.
-- 
View this message in context: http://www.nabble.com/Call-Oracle-stored-function-using-Hibernate-tf4429022.html#a12634650
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Call Oracle stored function using Hibernate

Posted by Antonio Petrelli <an...@gmail.com>.
2007/9/12, GEDA <ge...@gmail.com>:
>
>
> Hi. I am using Spring, Struts 2, Hibernate and Oracle as DB. Until now
> everything worked ok since I only needed full entity objects but now I
> have
> to call some stored functions from the DB using the hibernate api. Until
> now
> I have used the following syntax: Query q =
> getEntityManager().createQuery().
>
> Can you give me an example please on how to call a stored function ?



Ooookaaaayy let's say altogether:
this is a Struts forum, not an Hibernate forum!
And BTW, I think this page can help:
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#sp_query
(please do not reply to this email).

Antonio

[OT] Re: Call Oracle stored function using Hibernate

Posted by Dave Newton <ne...@yahoo.com>.
--- GEDA <ge...@gmail.com> wrote:
> now I have to call some stored functions from the DB

> using the hibernate api. 

You might want to ask this on a Hibernate list / forum
or STFW with a query resembling "hibernate +call
stored proc" or similar.

d.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Call Oracle stored function using Hibernate

Posted by Hayrol Reyes Mejía <Ha...@mhcp.gob.ni>.
Well, calling SP's is not a Struts topic (don't care the version), of course it's for Hibernate or even Oracle!!

Also, it has a lot to do with your persistence layer and Data Model design.

Anyway, you have several ways to call an Oracle SP function, here you have two hints:

a) Use Hibernate to map the SP using named query, as it is explained at http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#sp_query
and follow as you know.

b) Use standard code to call the SP and manage the return, something like this:
.....
String errors = null;
Connection con = myPersistence.getSession().connection();	   
try {
	CallableStatement cs = null; //a "simple" CallableStatement
	// now a call to the function with two parameters
	cs = con.prepareCall("{? = call PKG_VALIDATIONS.FNC_VALID1(?,?)}");
	
	cs.registerOutParameter(1,Types.VARCHAR); //the type of return
	cs.setInt(2,2007);				//the first param (a Int)
      cs.setString(3,"Agust");			//the second param
      cs.execute();					//execute the call
      errors = cs.getString(1);			//get the result
    }
.....

Of course it's a very small a simple example to validate some data using a Oracle SP function, and returning the errors found (if any) as a string.

Well, just take care what you are returning and how are you waiting the return in your call. Of course, there some limitations on what you can return from Oracle SP function and what you can get in your java app or persistence model, these limitations apply always.

Cya.


-----Mensaje original-----
De: GEDA [mailto:georgedadulescu@gmail.com] 
Enviado el: Miércoles, 12 de Septiembre de 2007 06:50 a.m.
Para: user@struts.apache.org
Asunto: Call Oracle stored function using Hibernate


Hi. I am using Spring, Struts 2, Hibernate and Oracle as DB. Until now
everything worked ok since I only needed full entity objects but now I have
to call some stored functions from the DB using the hibernate api. Until now
I have used the following syntax: Query q =
getEntityManager().createQuery(). 

Can you give me an example please on how to call a stored function ?

Thank you.
-- 
View this message in context: http://www.nabble.com/Call-Oracle-stored-function-using-Hibernate-tf4429022.html#a12634650
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org