gpt4 book ai didi

java - spring data spa 和 oracle 包

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:11:30 26 4
gpt4 key购买 nike

我正在尝试构建一个 spring boot rest 端点,该端点调用具有 2 个输入参数和 45 个约束参数的 oracle 存储过程。我创建了一个实体:

package com.me.data.userservice.models;

import javax.persistence.*;
import java.util.Date;

/**
* Created by me on 5/27/17.
*/
@Entity
@NamedStoredProcedureQueries({
@NamedStoredProcedureQuery(name = "getUserDetailsSp",
procedureName = "user_pkg.get_user_details",
parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, name = "p_in_user_id", type = Long.class),
@StoredProcedureParameter(mode = ParameterMode.IN, name = "p_in_region", type = String.class)
},
resultClasses = UserDetails.class)
})
public class UserDetails {
//region Private members
@Id
private Long user_id;
private String first_name;
private String last_name;
private String email;
@Column(name = "p_in_user_id", nullable = false)
private String userId;
private String user_id;
@Column(name = "p_in_region", nullable = false)
private String region;
private Long scnd_user_id;
...
}

还有一个存储库:

package com.me.data.userservice.repositories;

import com.me.data.userservice.models.UserDetails;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

/**
* Created by me on 5/27/17.
*/
public interface UserDetailsRepository extends CrudRepository<UserDetails, Long> {
@Procedure(name="getUserDetailsSp")
public UserDetails findByUserIdAndRegion(@Param("p_in_user_id") String userId, @Param("p_in_region") String region);
}

所有这些代码都可以正常编译,但是当我调用存储库时出现以下错误:

2017-05-27 18:41:27 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Object of class [org.springframework.data.jpa.repository.query.PartTreeJpaQuery] must be an instance of class org.springframework.data.jpa.repository.query.StoredProcedureJpaQuery; nested exception is java.lang.IllegalArgumentException: Object of class [org.springframework.data.jpa.repository.query.PartTreeJpaQuery] must be an instance of class org.springframework.data.jpa.repository.query.StoredProcedureJpaQuery] with root cause java.lang.IllegalArgumentException: Object of class [org.springframework.data.jpa.repository.query.PartTreeJpaQuery] must be an instance of class org.springframework.data.jpa.repository.query.StoredProcedureJpaQuery at org.springframework.util.Assert.instanceCheckFailed(Assert.java:389) at org.springframework.util.Assert.isInstanceOf(Assert.java:327) at org.springframework.util.Assert.isInstanceOf(Assert.java:339) at org.springframework.data.jpa.repository.query.JpaQueryExecution$ProcedureExecution.doExecute(JpaQueryExecution.java:300) at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:82) at...

出于某种原因,我无法解码此错误,并且无法在谷歌上找到任何帮助。

这一定是可能的,但我没有找到任何具有多个返回值或仅输入参数的示例。

添加细节

其实我刚刚才意识到我user_pkg.get_user_details其实是一个查询函数。这对我的应用有何影响?

最佳答案

我的解决方案或者我应该说我的解决方法有点不同,因为在尝试了很多事情之后我放弃了@NamedStoredProcedureQueries。所以,我通过 @Query 注释完成了

@Repository 
public interface MyObjectRepository extends CrudRepository<MyObject, String> {
@Query(value = "EXECUTE [dbo].[myProc] :fieldName, :pages", nativeQuery = true)
Set<MyObject> findAllByFieldName(@Param("fieldName") String fieldName, @Param("pages") int pages);
}

此链接可能会有帮助 DATA REPOSITORIES IN SPRING DATA JPA

关于java - spring data spa 和 oracle 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44222868/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com