I'm trying to call the following stored procedure from a hibernate mapping file.
Not sure if this is the correct way to call a stored procedure from Hiberanate.
All I want back is the String result back from the stored procedure.
In Hibernate to call a stored procedure, you can only return Reference cursors. And it must be the first out parameter.
Since you are using Spring, I recommend you look at the StoredProcedure class Spring has and use JDBCTemplate to run that code. I hate to say it this way, but because of some other vendor (Not Hibernate) not 100% implementing the JDBC spec caused all this trouble with Stored Procedures in Hibernate.
thanks for your response. I got the following error:-
Caused by: org.hibernate.MappingException: Named query not known: select PERSON_DETAILS(ID) from PERSON person where person.ID = 12345
There are rules and limitations for using stored procedures with Hibernate as Mark said.
Suppose you are using oracle , a function must return a result set, the first parameter of a procedure must be an OUT that returns a result set. This is done by using a SYS_REFCURSOR type in Oracle and you need to define a REF CURSOR type.
While these rules vary with different databases, if your functions or procedures do not satisfy these rules no matter what kind of changes have been done to your java codes or hbm.xml ,it won't work.
May be you could call stored procedure through JDBC connection(new Configuration().configure("hibernate.cfg.xml").buildSettings().getConnectionProvider().getConnection();) instead of Hibernate Session.
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad: