简体   繁体   English

如何使用spring和hibernate调用存储过程

[英]how to call stored procedure using spring and hibernate

I get an error message as java.lang.reflect.UndeclaredThrowableException and Invalid column name. 我收到一条错误消息,如java.lang.reflect.UndeclaredThrowableException和无效的列名。 Can you help me why am i getting this error. 您能帮我为什么我会收到此错误。

I suggest following the recommendation of the documentation: 我建议遵循文档的建议:

16.2.2.1. 16.2.2.1。 Rules/limitations for using stored procedures 使用存储过程的规则/限制

You cannot use stored procedures with Hibernate unless you follow some procedure/function rules. 除非遵循某些过程/功能规则,否则您不能在Hibernate中使用存储过程。 If they do not follow those rules they are not usable with Hibernate. 如果他们不遵守这些规则,则无法在Hibernate中使用。 If you still want to use these procedures you have to execute them via session.connection() . 如果仍然要使用这些过程,则必须通过session.connection()执行它们。 The rules are different for each database, since database vendors have different stored procedure semantics/syntax. 每个数据库的规则都不同,因为数据库供应商具有不同的存储过程语义/语法。

Stored procedure queries cannot be paged with setFirstResult()/setMaxResults() . 存储过程查询不能使用setFirstResult()/setMaxResults()进行分页。

The recommended call form is standard SQL92: { ? = call functionName(<parameters>) } 建议采用的调用方式是标准SQL92: { ? = call functionName(<parameters>) } { ? = call functionName(<parameters>) } or { ? = call procedureName(<parameters>} { ? = call functionName(<parameters>) }{ ? = call procedureName(<parameters>} { ? = call procedureName(<parameters>} . Native call syntax is not supported. { ? = call procedureName(<parameters>} 。不支持本机调用语法。

For Oracle the following rules apply: 对于Oracle ,适用以下规则:

  • A function must return a result set. 函数必须返回结果集。 The first parameter of a procedure must be an OUT that returns a result set. 过程的第一个参数必须是返回结果集的OUT。 This is done by using a SYS_REFCURSOR type in Oracle 9 or 10. In Oracle you need to define a REF CURSOR type. 这是通过在Oracle 9或10中使用SYS_REFCURSOR类型完成的。在Oracle中,您需要定义REF CURSOR类型。 See Oracle literature for further information. 有关更多信息,请参见Oracle文献。

For Sybase or MS SQL server the following rules apply: 对于Sybase或MS SQL Server,适用以下规则:

  • The procedure must return a result set. 该过程必须返回结果集。 Note that since these servers can return multiple result sets and update counts, Hibernate will iterate the results and take the first result that is a result set as its return value. 注意,由于这些服务器可以返回多个结果集和更新计数,因此Hibernate将迭代结果并将结果集的第一个结果作为其返回值。 Everything else will be discarded. 其他一切将被丢弃。
  • If you can enable SET NOCOUNT ON in your procedure it will probably be more efficient, but this is not a requirement. 如果您可以在过程中启用SET NOCOUNT ON ,则可能会更有效,但这不是必需的。

Once your code will be aligned with the rules, if you still get an error, please provide the full error message. 一旦您的代码与规则保持一致,如果仍然出现错误,请提供完整的错误消息。

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

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