简体   繁体   English

如何在spring框架中使用HibernateTemplate调用存储过程?

[英]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? 任何人都可以帮我在Spring框架中使用HibernateTemplate调用存储过程吗? I'm new to Hibernate, so please help me with this. 我是Hibernate的新手,所以请帮助我。

Thanks in advance, 提前致谢,

Sinu Mathews Sinu Mathews

在Hibernate中,存储过程只是命名查询的一个特例,您可以使用其中一个findByNamedQuery()方法使用HibernateTemplate执行命名查询。

you can not use HibernateTemplate to call your procedure, use getCurrentSession() method from SessionFactory or use getSession from HibernateTemplate. 你不能使用HibernateTemplate调用你的程序,使用SessionFactory中的getCurrentSession()方法或使用HibernateTemplate中的getSession。

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. 如果你的过程没有返回游标或函数,你可以使用findByNameQuery()方法,但是如果你的过程返回一些游标或函数,该方法将不起作用。

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM