How to call a stored procedure using HibernateTemplate in spring framework?
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 Ma开发者_C百科thews
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.
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;<br>
CallableStatement statement = con.prepareCall(<your procedure>);<br>
//some setting parameter for your procedure<br>
statement.execute();
精彩评论