【问题标题】:Spring Data and stored proceduresSpring数据和存储过程
【发布时间】:2016-04-27 17:53:11
【问题描述】:

我有一个带有以下声明的存储过程:

CREATE PROCEDURE GetAttributesForCategory(IN catId BIGINT(20))

在我的 Spring Boot 支持的应用程序中有一个实体:

@Entity
@NamedStoredProcedureQueries({
        @NamedStoredProcedureQuery(
                name = "ProductAttribute.getAttributesForCategory",
                procedureName = "GetAttributesForCategory",
                parameters = {
                        @StoredProcedureParameter(name = "catId", 
                                                    type = Long.class, 
                                                    mode = ParameterMode.IN)
                }
        )
})
public class ProductAttribute {
    ...
}

对应的存储库看起来像:

public interface ProductAttributeReposirory extends JpaRepository<ProductAttribute, Long> {

    @Procedure(name = "getAttributesForCategory")
    List<ProductAttribute> getAttributesForCategory(@Param("catId") Long catId);
}

都是按照this example做的,但是在Spring上下文加载过程中出现异常:

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'productAttributeRepository': Invocation of init method failed; 
nested exception is org.springframework.data.mapping.PropertyReferenceException: 
No property getAttributesForCategory found for type ProductAttribute!

我无法想象出了什么问题。有人可以吗?

【问题讨论】:

    标签: jpa stored-procedures spring-data spring-data-jpa


    【解决方案1】:

    我遇到了同样的问题,并通过添加 OUT @StoredProcedureParameter 解决了它:

    @StoredProcedureParameter(mode = ParameterMode.IN, name = "inVar", type = String.class), @StoredProcedureParameter(mode = ParameterMode.OUT, name = "outVar", type = ArrayList.class)

    虽然此时我得到一个不同的错误“2 的参数索引超出范围”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-26
      • 1970-01-01
      相关资源
      最近更新 更多