簡體   English   中英

分頁-使用Spring Data JPA訪問第二頁時出現UnsupportedOperationException

[英]Pagination - UnsupportedOperationException while accessing to the second page using Spring Data JPA

我想在當前應用程序中添加分頁。 為此,我有以下代碼:

MyEntity.java

@Entity
@Table(name="MY_ENTITY_1")
public class MyEntity {

    @Id
    @GeneratedValue
    @Column(name="P_ID")
    private Integer id;

    @Column(name = "C_CODEBRANCHE")
    private Integer codeBranche;

    // ...
}

MyEntityRepository.java

@Repository
public interface MyEntityRepository extends JpaRepository<MyEntity, Integer> {
}

MyServiceImpl.java

@Service
@Transactional
public class MyServiceImpl implements MyService {    
    @Autowired
    private MyEntityRepository myEntityRepository;

    @Override
    public Page<MyEntity> getEntities(Pageable pageable) {
        return myEntityRepository.findAll(pageable);
    }
}

還有MyResource.java

@RestController
@RequestMapping("/")
public class MyResource {
    @Autowired
    private MyService myService;

    @GetMapping(path = "/myentity")
    public Page<MyEntity> getEntities(Pageable pageable) {
        return myService.getEntities(pageable);
    }
}

當我稱“ / myentity”時,我有20個結果,這很正常。

當我叫“ / myentity?page = 0&size = 10”時,我有10條結果。

但是,當我呼叫“ / myentity?page = 1&size = 10”時,出現以下問題:

錯誤6864 --- [nio-8082-exec-1] oaccC [。[。[/]。[dispatcherServlet]:路徑為[]的Servlet [dispatcherServlet]的Servlet.service()引發異常[請求處理失敗; 嵌套的異常是java.lang.UnsupportedOperationException:不支持查詢結果偏移量]並有根本原因

java.lang.UnsupportedOperationException:org.hibernate.dialect.DB2400Dialect $ 1.processSql(DB2400Dialect.java:26)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]不支持查詢結果偏移量在org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1893)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final] ...

我真的不知道怎么回事。

也許您遇到了此錯誤HHH-10489 此錯誤已在Hibernate 5.2.4.Final中修復,然后應將Hibernate更新到該版本或更高版本。

將其放在您的application.yml中:

春天:jpa:屬性:休眠:legacy_limit_handler:true

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM