JPA:如何调用存储过程 [英] JPA: How to call a stored procedure
问题描述
我的项目中在sql/my_prod.sql下有一个存储过程
I have a stored procedure in my project under sql/my_prod.sql
我有我的功能delete_entity
以我的身份
@NamedNativeQuery(name = "delete_entity_prod",
query = "{call /sql/delete_entity(:lineId)}",
我叫
Query query = entityManager.createNamedQuery("delete_entity_prod")
setParameter("lineId",lineId);
我遵循以下示例: http://objectopia. com/2009/06/26/calling-stored-procedures-in-jpa/
,但不执行删除操作,也不发送任何错误.
but it does not execute the delete and it does not send any error.
我没有找到关于此的明确信息,我缺少什么吗?也许我需要先加载my_prod.sql
?但是如何?
I haven't found clear information about this, am I missing something? Maybe I need to load the my_prod.sql
first? But how?
推荐答案
这实际上是您创建查询的方式.
This is actually they way you create a query.
Query query = entityManager.createNamedQuery("delete_entity_prod")
setParameter("lineId",lineId);
要调用它,必须执行:
query.executeUpdate();
当然,数据库必须已经包含该过程.因此,如果您在SQL文件中定义了它,请查看
Of course, the DB must already contain the procedure. So if you have it defined in your SQL file, have a look at Executing SQL Statements from a Text File(this is for MySQL but other database systems use a similar approach to execute scripts)
这篇关于JPA:如何调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!