简体   繁体   English

spring-data-jpa 1.11.16带游标的存储过程

[英]spring-data-jpa 1.11.16 stored procedure with cursor

i'm unable to use stored procedure with cursor in spring-data-jpa (version 1.11.16) and an oracle server. 我无法在spring-data-jpa(版本1.11.16)和oracle服务器中使用带有游标的存储过程。

The Repository: 仓库:

@Repository
public interface GeoRegionRepository extends CrudRepository<PocRegions, String> {

    @Procedure(name = "PocRegions.getRegion", procedureName = "POC_PKG_GEO.PRO_RETURN_REGION")
    List<PocRegions> getRegion(@Param("id_region") BigDecimal regionId);
}

The annotation on the entity: 实体上的注释:

@Entity
@Table(name = "POC_REGIONS")
@NamedStoredProcedureQueries({
        @NamedStoredProcedureQuery( name = "PocRegions.getRegion", procedureName = "POC_PKG_GEO.PRO_RETURN_REGION",
                resultClasses = PocRegions.class ,parameters = {
                @StoredProcedureParameter(mode = ParameterMode.IN, name = "id_region", type = BigDecimal.class),
                @StoredProcedureParameter(mode = ParameterMode.REF_CURSOR, name = "o_cursor", type = Void.class)})
})

that's the java response when i invoke: 这是我调用时的Java响应:

geoRegionRepo.getRegion(id)

2018-12-11 13:07:26.047 DEBUG 24164 --- [nio-9090-exec-2] org.hibernate.SQL : {call POC_PKG_GEO.PRO_RETURN_REGION(?,?)} Hibernate: {call POC_PKG_GEO.PRO_RETURN_REGION(?,?)} 2018-12-11 13:07:27.410 TRACE 24164 --- [nio-9090-exec-2] ohtype.descriptor.sql.BasicBinder : binding parameter [id_region] as [NUMERIC] - [1] 2018-12-11 13:07:27.658 WARN 24164 --- [nio-9090-exec-2] .mmaExceptionHandlerExceptionResolver : Resolved [java.lang.UnsupportedOperationException: org.hibernate.dialect.Oracle9iDialect does not support resultsets via stored procedures] 2018-12-11 13:07:26.047调试24164-[nio-9090-exec-2] org.hibernate.SQL:{call POC_PKG_GEO.PRO_RETURN_REGION(?,?)}休眠:{呼叫POC_PKG_GEO.PRO_RETURN_REGION(? ,?)} 2018-12-11 13:07:27.410 TRACE 24164-[nio-9090-exec-2] ohtype.descriptor.sql.BasicBinder:绑定参数[id_region]为[NUMERIC]-[1] 2018 -12-11 13:07:27.658 WARN 24164 --- [nio-9090-exec-2] .mmaExceptionHandlerExceptionResolver:已解决[java.lang.UnsupportedOperationException:org.hibernate.dialect.Oracle9iDialect不支持通过存储过程的结果集]

I'm not sure if is possible to use cursor with this old version of spring-data or not. 我不确定是否可以在旧版本的spring-data中使用游标。 What sould i do to use spring-data-jpa and call the procedure? 我该怎么做才能使用spring-data-jpa并调用该过程?

Thank you 谢谢

EDIT 1: 编辑1:

i added into my application.properties the following line: 我将以下行添加到我的application.properties中:

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect

and added that to the pom (excluding hibernate conflict into spring-data-jpa dependency's declariation): 并将其添加到pom中(将休眠冲突排除到spring-data-jpa依赖项的声明中):

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-tools</artifactId>
    <version>${hibernate.version}</version>
</dependency>

Most likely the problem is not the version of spring-data, but Hibernate version and/or configuration. 问题很可能不是spring-data的版本,而是Hibernate的版本和/或配置。

Check carefully the error message: 仔细检查错误消息:

java.lang.UnsupportedOperationException: org.hibernate.dialect.Oracle9iDialect does not support resultsets via stored procedures java.lang.UnsupportedOperationException:org.hibernate.dialect.Oracle9iDialect不支持通过存储过程的结果集

The error says that the Oracle9 dialect used by Hibernate doesn't support reading data from stored procedures. 该错误表明Hibernate使用的Oracle9方言不支持从存储过程读取数据。 So, the problem's origin is Hibernate, not Spring Data. 因此,问题的根源是休眠,而不是Spring Data。

If you try a quick search using the error message you'll get this useful thread: 如果您尝试使用错误消息进行快速搜索,您将获得以下有用的线程:

java.lang.UnsupportedOperationException: org.hibernate.dialect.Oracle10gDialect does not support resultsets via stored procedures java.lang.UnsupportedOperationException:org.hibernate.dialect.Oracle10gDialect不支持通过存储过程的结果集

According to this post, I will probably need to upgrade your hibernate version to 5.1 and the dialect version (oracle 9 to 10). 根据这篇文章,我可能需要将您的休眠版本升级到5.1和方言版本(Oracle 9到10)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM