This is my hibernate configuration:
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(final DataSource dataSource,
final Environment env)
{
final LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource);
entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
entityManagerFactoryBean.setPackagesToScan("...");
final Properties jpaProperties = new Properties();
jpaProperties.put("hibernate.dialect", env.getRequiredProperty("hibernate.dialect"));
jpaProperties.put("hibernate.hbm2ddl.auto", env.getRequiredProperty("hibernate.hbm2ddl.auto"));
jpaProperties.put("hibernate.ejb.naming_strategy", env.getRequiredProperty("hibernate.ejb.naming_strategy"));
jpaProperties.put("hibernate.show_sql", env.getRequiredProperty("hibernate.show_sql"));
jpaProperties.put("hibernate.format_sql", env.getRequiredProperty("hibernate.format_sql"));
entityManagerFactoryBean.setJpaProperties(jpaProperties);
return entityManagerFactoryBean;
}
Now I want to make a query in HQL (using @Query(value = "query")) with standard pagination settings like offset and limit. I know about query.setMaxResults() and query.setFirstResult(), but for that I need a Session (or do I?), but I didn't use sessions to configure Hibernate.
Can I use annotations only to specify the offset and limit to queries? Is there a way to use HQL to programmatically simulate query.setMaxResults() and query.setFirstResult()?
PageandPageRequestobjects?PagingAndSortingRepository<T,ID>that your repository can implement to enable paging and sorting.