0

I am trying to implement Pagination in SpringBoot using SpringData and JPA. I have Repository which extends JPARepository.

this is my repository interface

public interface PartyRepository extends JpaRepository<PartyTo, String> {
    @Query("select c.id.trans0stat as trans0stat ,  c.eff0yr as eff0yr,  c.eff0mo as eff0mo, c.eff0da as eff0da,a.firstname...
    from PartyTo as a  , PartyAssociatedWithQuoteTO as b , ContractTO as  c , AddressTO as d WHERE  
    a.firstname=(case when :firstname is null then a.firstname else :firstname end) 
    and d.city=(case when :city is null then d.city else :city end)  and d.state=(case when :state is null then d.state else :state end)...  ")
    List quotesListByCriteria(@Param("firstname") String firstname, @Param("city") String city,.......@Param("state") String state ,Pageable pageable);

i am calling this repo from service like this after Autowiring the Repository

Pageable pageable = new PageRequest(page,size);    

List<Object[]> rowList = myRepo.quotesListByCriteria(quotes.getFirstName(), quotes.getCity(),...paraMonth,paraDate,pageable);

in application.properties i have

spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect

But when i run the project i get error

.18:22:06.027 [http-nio-8080-exec-2] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Incorrect syntax near '@P0'. 
.18:22:06.319 [http-nio-8080-exec-3] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Incorrect syntax near '@P0'. 
.18:22:06.694 [http-nio-8080-exec-2] WARN  o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Failed to invoke @ExceptionHandler method: public org.springframework.http.ResponseEntity<java.lang.Object> 
org.springframework.context.NoSuchMessageException: No message found under code 'could.not.extract.ResultSet;.SQL.[n/a];.nested.exception.is.org.hibernate.exception.SQLGrammarException:.could.not.extract.ResultSet' for locale 'en_US'.
    at org.springframework.context.support.AbstractMessageSource.getMessage(AbstractMessageSource.java:159)

Hibernate Version=5.2.10.Final

This is my Config class

This is my config class

@Configuration
@EnableSpringDataWebSupport
@EnableCaching
@EnableHypermediaSupport(type = { HypermediaType.HAL })
@ComponentScan(basePackages = { "com.data.config", "com.data.controller",
         "com.data.security.interceptor",   "com.data.service.options","com.data.filter"})
public class AppConfigQuotes extends WebMvcConfigurerAdapter {

    @Autowired
    SecurityInterceptor securityInterceptor;

    @Bean
    @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public OptionsImpl OptionsImpl() {
        return new OptionsImpl();

    }

    @Bean
    @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public GenericDaoJpaImpl gerericeDaoImpl() {
        return new GenericDaoJpaImpl();
    }

    @Bean
    @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public MessageLocalServiceImpl messageLocalServiceImpl() {
        return new MessageLocalServiceImpl();
    }

    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(securityInterceptor);
    }


    @Bean
    public JacksonUtils jacksonUtils() {
        return new JacksonUtils();
    }

    @Bean
    public CacheManager cacheManager() {
        return new EhCacheCacheManager(getEhCacheFactory().getObject());
    }

    @Bean
    public EhCacheManagerFactoryBean getEhCacheFactory() {
        EhCacheManagerFactoryBean factoryBean = new EhCacheManagerFactoryBean();
        factoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));
        factoryBean.setShared(true);
        return factoryBean;
    }

    @Bean
    public SchemaGenerator schemaGenerator() {
        return new SchemaGenerator();
    }

    @Bean(name = "RiskMapping")
    @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public RiskMappingProcessor riskMappingProcessor() {
        return new RiskMappingProcessor();
    }

    @Bean(name = "RiskService")
    @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public RiskServiceProcessor riskServiceProcessor() {
        return new RiskServiceProcessor();
    }

    @Bean
    @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public RiskHelper getCollectionResourceImpl() {
        return new RiskHelper();
      } 
    }
Bipul Kumar
  • 39
  • 1
  • 7
  • does the same query run without the `pageable` parameter both in interface, `myRepo.quotesListByCriteria(quotes.getFirstName(), quotes.getCity(),...paraMonth,paraDate);` and when calling it `List rowList = myRepo.quotesListByCriteria(quotes.getFirstName(), quotes.getCity(),...paraMonth,paraDate);`. I do not think it is a `pagination` problem but rather to the object returned from the query, what object is it? Do you have a class for it, is it `PartyTo`? – pleft Oct 09 '17 at 13:46
  • yes it works fine without the pageable, I have PartyTo as entity `@Entity public class PartyTo extends JPAEntity implements Serializable {}` – Bipul Kumar Oct 09 '17 at 13:54
  • Ok, have you identified what is this `'@P0'` in the stacktrace? can you post the `SQL` generated? – pleft Oct 09 '17 at 14:11
  • yes , it generate top query like this `select TOP ? contractto2_.TRANS0STAT as col_0_0_, ...` and it refers to the ? after TOP as P0 and then `o.h.e.jdbc.spi.SqlExceptionHelper - Incorrect syntax near '@P0'.` error is printed – Bipul Kumar Oct 09 '17 at 14:19
  • 1
    Yes ok, but please can you update your question and post the FULL `SQL` statement instead of `...` to see exactly what it is? – pleft Oct 09 '17 at 14:22
  • By any chance, do you have another `.properties` file where you might have declared the `hibernate dialect`? e.g. `hibernate.dialect = org.hibernate.dialect.SQLServerDialect`. Or maybe in your `application.properties` in some other lines than the ones posted in your question? – pleft Oct 09 '17 at 14:35
  • i have checked that and no where dialect is different its only `SQLServer2012Dialect `, also there is no issue with the query without `pageable ` – Bipul Kumar Oct 09 '17 at 14:47
  • By any chance do you have any `@Configuration` classes? can you post them too? – pleft Oct 10 '17 at 11:17
  • 1
    change dialect of `org.hibernate.dialect.SQLServerDialect` for `org.hibernate.dialect.SQLServer2008Dialect` or `org.hibernate.dialect.SQLServer2012Dialect`, depends of your version – Jeterson Miranda Gomes May 17 '18 at 20:57

0 Answers0