Spring 使用存储库调用存储过程
我试图通过Spring 使用存储库调用存储过程,spring,jpa,stored-procedures,Spring,Jpa,Stored Procedures,我试图通过crudepository方法(SpringJPA)调用数据库存储过程 这是我的存储库的代码 public interface TestRepo extends JpaRepository<NewsContainer, Long> { @Procedure(procedureName = "ncMaxVisualisations") public Long getMaxNumberOfVisualisations(); } 测试的输出是 testWithReposit
crudepository
方法(SpringJPA)调用数据库存储过程
这是我的存储库的代码
public interface TestRepo extends JpaRepository<NewsContainer, Long> {
@Procedure(procedureName = "ncMaxVisualisations")
public Long getMaxNumberOfVisualisations();
}
测试的输出是
testWithRepository()
Hibernate: {call ncMaxVisualisations(?)}
2014-10-24 17:47:28 WARN SqlExceptionHelper:144 - SQL Error: 0, SQLState: S1009
2014-10-24 17:47:28 ERROR SqlExceptionHelper:146 - Parameter number 1 is not an OUT parameter
testWithEM()
Hibernate: {call ncMaxVisualisations()}
50
若我使用repository调用存储过程,它将等待参数,而若我使用EntityManager调用它,它将正常工作。为什么?
谢谢你的支持
问候。
Mauro好的,Spring需要一个类型为OUT的参数,它将读取您的输出值 我为此做了一个测试: 程序:
create or replace PROCEDURE TESTPROCEDURE
(
TEST1 OUT NUMBER
) AS
BEGIN
TEST1 := 50;
END TESTPROCEDURE;
映射:
@Procedure(procedureName = "TESTPROCEDURE", outputParameterName = "TEST1")
public Long callTestProcedure();
希望有帮助:)
@Procedure(procedureName = "TESTPROCEDURE", outputParameterName = "TEST1")
public Long callTestProcedure();