首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >org.hibernate.engine.jdbc.spi.SqlExceptionHelper -无效的参数索引2

org.hibernate.engine.jdbc.spi.SqlExceptionHelper -无效的参数索引2
EN

Stack Overflow用户
提问于 2019-09-03 20:00:35
回答 1查看 231关注 0票数 0

我正在将我的应用程序升级到Java8,hibernate5和Spring4。有一些现有的JPQL query,我在其中使用了可分页,更新后不能工作。我的情况越来越糟了

代码语言:javascript
运行
复制
2019-09-03 07:55:18,814 [http-nio-8080-exec-1] WARN  org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 07009
2019-09-03 07:55:18,815 [http-nio-8080-exec-1] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Invalid parameter index 2.

我尝试将返回类型从List更改为Page,但没有成功

代码语言:javascript
运行
复制
My POM.xml
<dependency>
     <groupId>org.hibernate</groupId>
     <artifactId>hibernate-core</artifactId>
    <version>5.2.10.Final</version>
</dependency>
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
         <version>1.4.3.RELEASE</version>
</dependency>

Repository 
@Query("select u from UserPasswordHistory as u where u.userId = ?1 order by createDate desc")   
    public List<UserPasswordHistory> findUserPasswordHistroy(Long userId, Pageable page);

Service
public List<UserPasswordHistory> findUserPasswordHistroy(Long userId, int resultLimit){
        try{
            Pageable topResult = new PageRequest(0,resultLimit);
            return pwdHistriyRepository.findUserPasswordHistroy(userId,topResult);

Entity
@Entity
@Table(name="user_password_history")
@Configurable(preConstruction = true, autowire = Autowire.BY_TYPE)
public class UserPasswordHistory implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "seq_id")
    private Long id;

    /**
     */
    @Column(name = "user_id")
    private Long userId;

    @Column(name = "password")
    private String password;

我需要进行分页

EN

Stack Overflow用户

发布于 2019-09-03 22:37:48

你可以使用Spring数据仓库的神奇方法,这里不需要使用@Query。请尝试:

代码语言:javascript
运行
复制
public interface UserPasswordHistoryRepository extends JpaRepository<UserPasswordHistory, Long> {
    List<UserPasswordHistory> findByUserIdOrderByCreateDateDesc(Long userId, Pageable pageable);
}

例如,要进行测试:

代码语言:javascript
运行
复制
userPasswordHistoryRepository.findByUserIdOrderByCreateDateDesc(1L, PageRequest.of(0, 2));
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57771355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档