Ошибка при вызове функции postgres с использованием JPA Spring data через @NamedStoredProcedureQuery

#postgresql #spring-boot #hibernate #spring-data-jpa #ref-cursor

Вопрос:

Версия весенней загрузки : 2.5.0

Я пытаюсь вызвать функцию, хранящуюся в базе данных Postgres, через Spring Data JPA .

Функция базы данных — (Возвращает курсор ссылки для результирующего набора, объединяющего данные из разных таблиц)

 CREATE OR REPLACE FUNCTION public.dbFunction(OUT outp refcursor, in_1 text, in_2 text, in_3 text, in_4 text)
 RETURNS refcursor
 LANGUAGE plpgsql
AS $function$
BEGIN
OPEN outp FOR
    <body>
$function$
;
 

При использовании @NamedStoredProcedureQuery и @Procedure
возникла ошибка : org.postgresql.util.PSQLException: Имя столбца appl_id не было найдено в этом наборе результатов.

В нем говорится, что имя столбца appl_id не найдено в наборе результатов, но в сущности имя столбца — applId- без подчеркивания. Почему он вставляет подчеркивание в имя столбца?

При запуске функции в бд я проверил , что имя столбца в результирующем наборе только applId — без подчеркивания

 @NamedStoredProcedureQuery(name = "ThisEntity.dbFunction",
procedureName = "dbFunction",
resultClasses = ThisEntity.class,
parameters = {
                @StoredProcedureParameter(mode = ParameterMode.REF_CURSOR, type = void.class),
                @StoredProcedureParameter(mode = ParameterMode.IN,  type = String.class),
                @StoredProcedureParameter(mode = ParameterMode.IN,  type = String.class),
                @StoredProcedureParameter(mode = ParameterMode.IN,  type = String.class),
                @StoredProcedureParameter(mode = ParameterMode.IN,  type = String.class)
})
@Entity
public class ThisEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    // Fields
    @Id
    @Column(name = "id")
    private Integer id;
    
   @Column(name = "applId")
    private Integer applId;
}

@Repository
public interface ThisEntityRepository
        extends CrudRepository<ThisEntity, Integer> {

    
      @Procedure(name = "ThisEntity.dbFunction")
      Set<ThisEntity> dbFunction(
      @Param("in_1") String in1,
      @Param("in_2") String in2,
      @Param("in_3") String in3,
      @Param("in_4") String in4);
     
}

@RestController
public class TestController {
    
    
    @Autowired
    ThisEntityRepository repo;
    
    @GetMapping("/getDetails")
    public String index() {
        System.out.println("in controller ");
        Set<ThisEntity> res =  repo.dbFunction("in1", "in2", "in3", "in4");
        System.out.println("res size:"   res.size());
        return "Greetings from Spring Boot!";
    }

LOG : 

in controller 
Hibernate: {? = call dbFunction(?,?,?,?)}
2021-10-20 22:45:24.650  WARN 10328 --- [io-28080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 42703
2021-10-20 22:45:24.651 ERROR 10328 --- [io-28080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : The column name appl_id was not found in this ResultSet.
2021-10-20 22:45:24.803 ERROR 10328 --- [io-28080-exec-2] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/test-boot] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Error extracting results from CallableStatement; SQL [GET_AUTHZ_APPL_FUNCTIONS]; nested exception is org.hibernate.exception.SQLGrammarException: Error extracting results from CallableStatement] with root cause

org.postgresql.util.PSQLException: The column name appl_id was not found in this ResultSet.
    at org.postgresql.jdbc.PgResultSet.findColumn(PgResultSet.java:2748) ~[postgresql-42.2.20.jar:42.2.20]
    at org.postgresql.jdbc.PgResultSet.getInt(PgResultSet.java:2626) ~[postgresql-42.2.20.jar:42.2.20]
    at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$2.doExtract(IntegerTypeDescriptor.java:62) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:257) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:243) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:329) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:3130) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1869) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.loader.Loader.hydrateEntityState(Loader.java:1797) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1770) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.loader.Loader.getRow(Loader.java:1622) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:740) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.loader.Loader.getRowsFromResultSet(Loader.java:1039) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.loader.Loader.processResultSet(Loader.java:990) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.result.internal.OutputsImpl$CustomLoaderExtension.processResultSet(OutputsImpl.java:321) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.result.internal.OutputsImpl.extractResults(OutputsImpl.java:140) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.procedure.internal.ProcedureOutputsImpl.access$500(ProcedureOutputsImpl.java:26) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.procedure.internal.ProcedureOutputsImpl$ProcedureCurrentReturnState.lambda$buildExtendedReturn$0(ProcedureOutputsImpl.java:95) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.result.internal.ResultSetOutputImpl.getResultList(ResultSetOutputImpl.java:41) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at org.hibernate.procedure.internal.ProcedureCallImpl.getResultList(ProcedureCallImpl.java:724) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
    at