我要从Java代码执行的mssql服务器上具有以下过程
DECLARE @RC int
DECLARE @newUid bigint
EXECUTE @RC = [TEST_DB].[foobar].[getNextUid] @newUid OUTPUT
在我的代码中,我定义了一个实体,并使用NamedStoredProcedureQuery批注定义了它
@Entity
@NamedStoredProcedureQuery(
name = "foobar.getNextUid",
procedureName = "foobar.getNextUid",
parameters = {
@StoredProcedureParameter(mode = ParameterMode.OUT, type = Long.class, name = "newUid")
}
)
当我在测试中调用此存储过程时,它将引发异常
java.lang.IllegalArgumentException: No @NamedStoredProcedureQuery was found with that name : foobar.getNextUid
我也尝试了将注释中的参数命名为@newUid
这是我的测试用例
EntityManager entityManager = managerEntityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
StoredProcedureQuery query = entityManager.createNamedStoredProcedureQuery("foobar.getNextUid");
query.setParameter("@newUid", 1);
long nextUid = (long) query.getOutputParameterValue("newUid");
entityManager.getTransaction().commit();
entityManager.close();
答案 0 :(得分:0)
尝试更换 query.getOutputParameterValue(“ @ newUid”); 通过 query.getOutputParameterValue(“ newUid”);