Spring Boot + Hibernate + JPA = именованный oracle вызов процедуры с использованием репозитория завершается неудачно - PullRequest
0 голосов
/ 29 февраля 2020

Интересно, почему:

  1. usingRepo не работает, в то время как usingEntityManager отлично работает
  2. ' org.hibernate.procedure. ParameterStrategyException: Попытка получить доступ к позиционному параметру [1], но MethodCall с использованием именованных параметров 'генерируется после создания единственного именованного параметра (добавьте' name = "po_list" "к @StoredProcedureParameter и 'outputParameterName =" po_list "" к @ Процедура)

Попытка без результата:

  1. заменить 'resultClasses = ReferenceInsurance.class,'
  2. заменить 'type = void.class' на type = Class.class и with type = ReferenceInsurance.class

Приложение:

package org.nyulmc.db;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import javax.persistence.EntityManager;
import java.util.List;

@SpringBootApplication(scanBasePackages = "org.nyulmc.db")
@EnableJpaRepositories(basePackages = "org.nyulmc.db")
@EnableAutoConfiguration
public class DbPackageOnly {

    @Bean
    public Object usingEntityManager(EntityManager em) {
        final List<ReferenceInsurance> list = em.createNamedStoredProcedureQuery("getRefEpicWebListNew").getResultList();
        return list;
    }

    @Bean
    public Object usingRepo(Repo repo) {
        final List<ReferenceInsurance> refEpicWebListNew = repo.getRefEpicWebListNew();
        return refEpicWebListNew;
    }

    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(DbPackageOnly.class);
        springApplication.setAdditionalProfiles("ora_dev");
        springApplication.run(args);
    }

}

Исключение:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.Object]: Factory method 'usingRepo' threw exception; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.util.ArrayList<?>] to type [@javax.transaction.Transactional @org.springframework.data.jpa.repository.query.Procedure java.util.List<org.nyulmc.db.ReferenceInsurance>] for value '[oracle.jdbc.driver.ForwardOnlyResultSet@6dcdc378]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [oracle.jdbc.driver.ForwardOnlyResultSet] to type [@javax.transaction.Transactional @org.springframework.data.jpa.repository.query.Procedure org.nyulmc.db.ReferenceInsurance]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:583)
    ... 16 common frames omitted
Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.util.ArrayList<?>] to type [@javax.transaction.Transactional @org.springframework.data.jpa.repository.query.Procedure java.util.List<org.nyulmc.db.ReferenceInsurance>] for value '[oracle.jdbc.driver.ForwardOnlyResultSet@6dcdc378]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [oracle.jdbc.driver.ForwardOnlyResultSet] to type [@javax.transaction.Transactional @org.springframework.data.jpa.repository.query.Procedure org.nyulmc.db.ReferenceInsurance]
    at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:47)
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:191)
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:212)
    at org.springframework.data.repository.core.support.QueryExecutionResultHandler.postProcessInvocationResult(QueryExecutionResultHandler.java:116)
    at org.springframework.data.repository.core.support.QueryExecutionResultHandler.postProcessInvocationResult(QueryExecutionResultHandler.java:69)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:592)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
    at com.sun.proxy.$Proxy109.getRefEpicWebListNew(Unknown Source)
    at org.nyulmc.db.DbPackageOnly.usingRepo(DbPackageOnly.java:25)
    at org.nyulmc.db.DbPackageOnly$$EnhancerBySpringCGLIB$$e28c25f.CGLIB$usingRepo$0(<generated>)
    at org.nyulmc.db.DbPackageOnly$$EnhancerBySpringCGLIB$$e28c25f$$FastClassBySpringCGLIB$$b08d6b62.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365)
    at org.nyulmc.db.DbPackageOnly$$EnhancerBySpringCGLIB$$e28c25f.usingRepo(<generated>)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 17 common frames omitted
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [oracle.jdbc.driver.ForwardOnlyResultSet] to type [@javax.transaction.Transactional @org.springframework.data.jpa.repository.query.Procedure org.nyulmc.db.ReferenceInsurance]
    at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321)
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194)
    at org.springframework.core.convert.support.CollectionToCollectionConverter.convert(CollectionToCollectionConverter.java:89)
    at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41)
    ... 49 common frames omitted

Зависимости Gragle:

plugins {
    id "io.spring.dependency-management" version "1.0.9.RELEASE"
    id 'org.springframework.boot' version '2.0.9.RELEASE'
    ...
}
dependencies {
    implementation('org.springframework.boot:spring-boot-starter-data-jpa')
    ...
}

Oracle подпись процедуры:

PROCEDURE get_RefEpicWebListNew(po_list OUT mycursor)

Репо:

package org.nyulmc.db;

import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.Repository;

import javax.transaction.Transactional;
import java.util.List;


public interface Repo extends Repository<ReferenceInsurance, Long> {

    @Transactional
    @Procedure(name = "getRefEpicWebListNew")
    List<ReferenceInsurance> getRefEpicWebListNew();

}

Объект:

package org.nyulmc.db;

import javax.persistence.*;

@NamedStoredProcedureQueries({
        @NamedStoredProcedureQuery(
                name = "getRefEpicWebListNew",
                procedureName = "DTIPDUSER.PD_REF_PKG.get_RefEpicWebListNew",
                resultClasses = ReferenceInsurance.class,
                parameters = {
                        @StoredProcedureParameter(mode = ParameterMode.REF_CURSOR, type = void.class)
                }
        )})
@Entity
public class ReferenceInsurance {

    @Id
    @Column(name = "benefit_plan_id")
    private Long benefitPlanId;

    @Column(name = "display_plan_name")
    private String displayPlanName;

    public Long getBenefitPlanId() {
        return benefitPlanId;
    }

    public void setBenefitPlanId(Long benefitPlanId) {
        this.benefitPlanId = benefitPlanId;
    }

    public String getDisplayPlanName() {
        return displayPlanName;
    }

    public void setDisplayPlanName(String displayPlanName) {
        this.displayPlanName = displayPlanName;
    }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...