2015-01-14 31 views
3

我正在使用spring-data-jpa + hibernate。 1.I碰上以下例外 ......「java.lang.IllegalArgumentException:具有該位置[1]的參數不存在」當我使用spring-data-jpa

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:?] 

......

  • 相信異常來自

    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); 
    } 
    
  • ,因爲我從PARAMS功能findExps的擺脫規格規格後,它工作得很好,我只想補充規範查詢。

    BYW,FamousExperience擴展BriefInfomation。我使用JPA Query的「構造函數表達式」功能,當我嘗試查詢時,我不需要屬性「內容」。

    @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

    如果你有規範規範在那裏,你將需要在你的查詢中的某處引用它...重要的是,它似乎當你有一個可分頁的那裏然後計數器不是從0開始,但在?1

    所以這樣的事情應該工作

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