我正在使用jpa**+hib。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;
}
}
请帮帮我!
1条答案
按热度按时间lsmepo6l1#
如果您有Specification spec在那里,您将需要在您的查询中的某个地方引用它...重要的是,它看起来像当您有一个可分页在那里,然后计数器不是从-0而是从-1开始
所以像这样东西应该能用