Java Tutorial/JPA/Pageable ResultSet

Материал из Java эксперт
Перейти к: навигация, поиск

Pageable ResultSet

File: Main.java



import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class Main {
  static EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPAService");
  static EntityManager em = emf.createEntityManager();
  public static void main(String[] a) throws Exception {
    em.getTransaction().begin();
    int currentPage = 2; 
    int pageSize = 80;
    
    List list = em.createNamedQuery("findAllStudents")
    .setFirstResult(currentPage * pageSize)
    .setMaxResults(pageSize)
    .getResultList();
   
    em.getTransaction().rumit();
    em.close();
    emf.close();
    Helper.checkData();
  }
}