
[英]findAll() using JpaRepository cause an exception - SpringBoot
[英]Array parameters to a postgresql function with SpringBoot/JpaRepository
我试图从 JpaInterface 调用 postgresql function,但我不知道为什么它不能工作。 我试图制作一个非常简单的 function 来弄清楚但找不到答案。 你能帮我么? 提前致谢。
public interface Interface extends JpaRepository<Model,Integer> {
@Procedure("test_proc")
int testProc(List<Integer> array);
}
下面是 sql function:
CREATE OR REPLACE FUNCTION public.test_proc(p_nbs integer[])
RETURNS integer
LANGUAGE plpgsql
AS $function$
declare
begin
return array_length(p_nbs, 1);
end;
$function$
;
我想知道放什么而不是 List 以及如何调用testProc
。
谢谢
我为我的问题找到了一些东西,但对解决方案不满意:
Session session = entityManager.unwrap(Session.class);
session.doWork(connection -> {
final CallableStatement callable = connection.prepareCall("select func_testArr(?)");
final Integer[] strings = {1, 2, 3};
final Array stringsArray = connection.createArrayOf("int", strings);
callable.setArray(1, stringsArray);
callable.execute();
});
我更喜欢将注释@Procedure
与 JPA 一起使用的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.