gpt4 book ai didi

java - "java.lang.IllegalArgumentException: Parameter with that position [1] did not exist"当我使用spring-data-jpa

转载 作者:搜寻专家 更新时间:2023-11-01 03:51:04 34 4
gpt4 key购买 nike

我正在使用 spring-data-jpa+hibernate。1.我遇到以下异常……

Caused by: java.lang.IllegalArgumentException: Parameter with that position [1] did not exist
at org.hibernate.jpa.spi.BaseQueryImpl.findParameterRegistration(BaseQueryImpl.java:518) ~[BaseQueryImpl.class:4.3.7.Final]
at org.hibernate.jpa.spi.BaseQueryImpl.setParameter(BaseQueryImpl.java:674) ~[BaseQueryImpl.class:4.3.7.Final]
at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:198) ~[AbstractQueryImpl.class:4.3.7.Final]
at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:49) ~[AbstractQueryImpl.class:4.3.7.Final]
at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:165) ~[ParameterBinder.class:?]
at org.springframework.data.jpa.repository.query.StringQueryParameterBinder.bind(StringQueryParameterBinder.java:66) ~[StringQueryParameterBinder.class:?]

……

  1. 我相信异常来自

    public interface FamousExperienceDao extends PagingAndSortingRepository<FamousExperience,
    Long>,JpaSpecificationExecutor<FamousExperience>
    {
    @Query( value =
    "select new com.tujia.community.entity.BriefInfomation(f.id,f.title,f.summary,f.thumbnail,f.author, f.issueDate, f.counter) from FamousExperience f"
    ,countQuery ="select count(f.id) from FamousExperience f")
    public Page<BriefInfomation> findExps(Specification<FamousExperience> spec, Pageable pgbl);
    }

因为在我从函数 findExps 的参数中去掉 Specification spec 之后,它运行良好,我只想为查询添加规范。

BYW,FamousExperience 类扩展了 BriefInfomation。我使用了 JPA 查询的“构造函数表达式”功能,我只是在尝试查询时不需要属性“内容”。

@Entity
@Table(name = "famous_experience")
public class FamousExperience extends BriefInfomation
{
private String content;

/**
* @return the content
*/
public String getContent()
{
return content;
}

/**
* @param content the content to set
*/
public void setContent(String content)
{
this.content = content;
}
}

请帮帮我!

最佳答案

如果你在那里有规范规范,你将需要在你的查询中的某个地方引用它......重要的是,当你在那里有一个可分页时,计数器似乎不是从 ?0 开始,而是从 ?1

所以这样的事情应该可行

 @Query( value = 
"from FamousExperience f where f.spec = ?1"
,countQuery ="select count(f.id) from FamousExperience f")

关于java - "java.lang.IllegalArgumentException: Parameter with that position [1] did not exist"当我使用spring-data-jpa,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27936905/

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