[英]Error: Parameter out was not defined for stored procedure
When I call this stored procedure: 当我调用此存储过程时:
procedure [dbo].[pTest]
@Date varchar(max) =null
as
begin
select * from test
end
from java using Spring Data JPA 1.10.2 with com.microsoft.sqlserver's sqljdbc 4.2. 从Java使用Spring Data JPA 1.10.2和com.microsoft.sqlserver的sqljdbc 4.2一起使用。 I get no error.
我没有错。 But when I add another parameter to the procedure
但是当我向过程添加另一个参数时
procedure [dbo].[pTest]
@ReportData varbinary(max) out
,@Date varchar(max) =null
as
begin
select * from test
end
I get the following error: 我收到以下错误:
2016-10-06 15:50:16.283 DEBUG 32604 --- [ main] c.m.s.jdbc.internals.SQLServerException : *** SQLException:SQLServerCallableStatement:9 com.microsoft.sqlserver.jdbc.SQLServerException: Parameter out was not defined for stored procedure pTest. Parameter out was not defined for stored procedure pTest.
2016-10-06 15:50:16.289 DEBUG 32604 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : Error preparing CallableStatement [pTest]
com.microsoft.sqlserver.jdbc.SQLServerException: Parameter out was not defined for stored procedure pTest.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:191) ~[sqljdbc-4.2.jar:na]
If I remove the @Date
parameter and modify the code accordingly, I get no error. 如果删除
@Date
参数并相应地修改代码,则不会出错。 Once I add back the @Date
parameter to have two parameters, I get the error again. 一旦我将
@Date
参数添加回具有两个参数,我将再次收到错误。 Why? 为什么?
The code for two params is as follows: 两个参数的代码如下:
@Entity
@NamedStoredProcedureQuery(name = "Test.getTest", procedureName = "pTest", parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, name = "Date", type = String.class),
@StoredProcedureParameter(mode = ParameterMode.OUT, name = "ReportData", type = byte[].class)
})
public class Test {
// serves no purpose other than to meet
// JPA requirement
@Id
private byte[] reportData;
}
Spring data repository: Spring数据存储库:
public interface TestRepository extends Repository<Test, Long> {
@Procedure("pTest")
byte[] get(@Param("Date") String date);
}
Test code: 测试代码:
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional(transactionManager="transactionManager")
public class TestRepositoryTest {
@Autowired
private TestRepository testRepository;
@Test
public void testGet() throws SQLException {
byte[] blob = testRepository.get("hi");
//error occurs
}
}
Found the issue :) The attribute name of @NamedStoredProcedureQuery
needs to match the repository method name. 发现了问题:)
@NamedStoredProcedureQuery
的属性名称需要与存储库方法名称匹配。 So change this: 所以改变这个:
@Entity
@NamedStoredProcedureQuery(name = "Test.getTest", procedureName = "pTest", parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, name = "Date", type = String.class),
@StoredProcedureParameter(mode = ParameterMode.OUT, name = "ReportData", type = byte[].class)
})
to this: 对此:
@Entity
@NamedStoredProcedureQuery(name = "Test.get", procedureName = "pTest", parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, name = "Date", type = String.class),
@StoredProcedureParameter(mode = ParameterMode.OUT, name = "ReportData", type = byte[].class)
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.