23

Mam prostej procedury przechowywanej używam do przetestowania funkcji Spring Data JPA Stored Procedure.Dane wiosny Parametry JPA NamedStoredProcedureQuery wielokrotnego wyświetlania

create or replace procedure plus1inout (arg in int,res1 out int,res2 out int) is 
BEGIN 
res1 := arg + 1; 
res2 := res1 + 1; 
END; 

Mój kod to:

@Repository 
public interface AdjudConverDateSPRepository extends JpaRepository<AdjudConverDateSP, Long> { 
    @Procedure(name = "plus1") 
    Object[] plus1(@Param("arg") Integer arg); 
} 

@Entity 
@NamedStoredProcedureQuery(name = "plus1", procedureName = "ADJUD.PLUS1INOUT", 
     parameters = { 
     @StoredProcedureParameter(mode = ParameterMode.IN, name = "arg", type = Integer.class), 
     @StoredProcedureParameter(mode = ParameterMode.OUT, name = "res1", type = Integer.class), 
     @StoredProcedureParameter(mode = ParameterMode.OUT, name = "res2", type = Integer.class) 
}) 
public class AdjudConverDateSP implements Serializable { 
     //stub to satisfy hibernate identifier requirement 
     @Id @GeneratedValue 
     private Long id; 

} 

Wszystko działa poprawnie, gdy mam jeden parametr wyjściowy. Ale po dodaniu drugiego parametru OUT otrzymuję wyjątek mówiąc, że nie można znaleźć procedury w encji.

Caused by: 
    org.springframework.data.mapping.PropertyReferenceException: No property plus1 found for type AdjudConverDateSP! at 
    org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75) at 
    org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327) at 
    org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307) at 
    org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270) at 
    org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241) at 
    org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) at 
    org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:235) at 
    org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373) at 
    org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:353) 
+0

W jakiej wersji Spring Data JPA używasz? –

+0

Spring-Data JPA wersja 1.8.0 –

+0

Istnieje problem w repozytorium git dla tego https://github.com/spring-projects/spring-data-examples/issues/80 ... to byłaby odpowiedź, gdy dostać się do tego. –

Odpowiedz

5

Wygląda @Procedure oczekuje tylko jeden parametr, który jest binded OUT bezpośrednio do rodzaju metoda powrotnej ...

Aby obsługiwać wiele OUT params można użyć API WZP bezpośrednio:

StoredProcedureQuery proc = em.createNamedStoredProcedureQuery("plus1"); 

proc.setParameter("arg", 1); 
proc.execute(); 
Integer res1 = (Integer) proc.getOutputParameterValue("res1"); 
Integer res2 = (Integer) proc.getOutputParameterValue("res2"); 
... 
+0

Ostatecznie za pomocą JPA API jest to, co zrobiłem. Gdzie się znalazłeś, że @Procedure spodziewa się tylko jednego parametru OUT? –

+1

Interfejs API zawiera tylko jeden parametr OUT http://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/repository/query/Procedure.html –

+0

. Czy możesz podać pełny przykład. Jestem nowy i nie mogę zadzwonić do procedury nazwanej przechowywanej poprzez menedżera jednostek. –