SpringBoot中的分页错误“@ P0'附近的语法不正确”

时间:2017-10-09 13:32:16

标签: spring hibernate spring-boot pagination spring-data-jpa

我正在尝试使用SpringData和JPA在SpringBoot中实现分页。 我有Repository,它扩展了JPARepository。

这是我的存储库界面

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

我在Autotiring the Repository

之后从这样的服务中调用这个repo
Pageable pageable = new PageRequest(page,size);    

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

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

但是当我运行项目时我得到错误

.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

这是我的Config类

这是我的配置类

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

0 个答案:

没有答案