Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to execute a Stored Proc in Hibernate

 
Nilesh Raje
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

Here is my problem. I need to invoke a stored proc that gives me a ID back to insert in a new row.
I googled about it and found that you can use names query but for that you need to map that into Hbb.xml file. I am using hibernate 3 and do not use HBM file for mapping . It uses Annotations for mapping of POJOS.
How can i used annotation to invoke a stored proc in SYBASE from Java code.?

Thanks a ton.!
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I googled about it and found that you can use names query but for that you need to map that into Hbb.xml file.


You can put the named query in you annotation POJO. I don't know if it works with stored procedures.
put your query after your import statement


[ August 25, 2007: Message edited by: Mathias Nilsson ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am little bit confused on one part. Is this an Insert Trigger like stored procedure. Or are you creating a Stored Procedure just so you can get the ID of that inserted record back? For the first part, when you call saveOrUpdate or persist it returns an Object back with its ID filled in, so you can already get that ID back in your application.

Mark
 
Sudhakar Vaddi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Spritzler:
I am little bit confused on one part. Is this an Insert Trigger like stored procedure. Or are you creating a Stored Procedure just so you can get the ID of that inserted record back? For the first part, when you call saveOrUpdate or persist it returns an Object back with its ID filled in, so you can already get that ID back in your application.

Mark


Mark,

I have seen many of your valuable responses in forum.

I have a question for you now.

I have a requirement like calling stored procedure with one OUT param and 10 IN params which returs n-columns and n-rows. How do I do this?

I dont have specfic mapping object to map in mapping file. I am expecting a list which conains list of rows.

Can you pls suggest me with a sample example for this.

Thanks in advance !

Cheers
Sudhakar
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sudhakar Vaddi:


Mark,

I have seen many of your valuable responses in forum.

I have a question for you now.

I have a requirement like calling stored procedure with one OUT param and 10 IN params which returs n-columns and n-rows. How do I do this?

I dont have specfic mapping object to map in mapping file. I am expecting a list which conains list of rows.

Can you pls suggest me with a sample example for this.

Thanks in advance !

Cheers
Sudhakar


Well, based on how you put the "returns" I don't think you will be able to accomplish that. One of the stipulations for Hibernate and using stored procedures is that the Out paramater must be a RefCursor. It cannot be anything else, not a custom datatype.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic