Stalyon
Stalyon

Reputation: 578

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

I want to add pagination to my current application. To do that, I have the following code:

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);
    }
}

And MyResource.java

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

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

When I call "/myentity", I have 20 results, and that's normal.

When I call "/myentity?page=0&size=10", I have 10 results.

But, when I call "/myentity?page=1&size=10", I have the following issue:

ERROR 6864 --- [nio-8082-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.UnsupportedOperationException: query result offset is not supported] with root cause

java.lang.UnsupportedOperationException: query result offset is not supported at org.hibernate.dialect.DB2400Dialect$1.processSql(DB2400Dialect.java:26) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1893) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] ...

I really have no idea what's going wrong.

Upvotes: 1

Views: 3764

Answers (2)

Sergio Teran
Sergio Teran

Reputation: 11

Put this in your application.yml:

spring: jpa: properties: hibernate: legacy_limit_handler: true

Upvotes: 1

Javvano
Javvano

Reputation: 1059

perhaps you faced this bug HHH-10489. this bug has fixed at Hibernate 5.2.4.Final, then you should update Hibernate to that or more late version.

Upvotes: 3

Related Questions