views:

337

answers:

2

Hi Experts,

Can anyone help me with calling a stored procedure using HibernateTemplate in spring framework? I'm new to Hibernate, so please help me with this.

Thanks in advance,

Sinu Mathews

+1  A: 

In Hibernate, stored procedures are just a special case of named queries, and you execute named queries with HibernateTemplate using one of the findByNamedQuery() methods.

skaffman
A: 

you can not use HibernateTemplate to call your procedure, use getCurrentSession() method from SessionFactory or use getSession from HibernateTemplate.

you can use findByNameQuery() method if your procedure doesn't return cursor or function, but the method will not work if your procedure returning some cursor or function.

if that is happened you have to get the Connection from your Session

java.sql.Connection con = getSession().connection;
CallableStatement statement = con.prepareCall();
//some setting parameter for your procedure
statement.execute();

Yudhi Karunia Surtan