Java 带有类似实体参数的JPA@Query

Java 带有类似实体参数的JPA@Query,java,spring,spring-data-jpa,Java,Spring,Spring Data Jpa,我在我的存储库中对JPA使用@Query。但是,当我执行一个使用这个@Query的程序时,我得到了这个错误: java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoader

我在我的存储库中对JPA使用
@Query
。但是,当我执行一个使用这个@Query的程序时,我得到了这个错误:

java.lang.IllegalStateException: Failed to load ApplicationContext

    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'supplierRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract XXX.Supplier XXXXX.SupplierRepository.findByNumber(XXXXX.Supplier)!
这是查询的代码:

@Query("SELECT s FROM Supplier WHERE s.number= :#{#supplier.number}")
Supplier findByNumber(@Param("supplier") Supplier supplier);

为什么会出现此错误?

您需要为实体提供别名,如下所示:

@Query("SELECT s FROM Supplier s WHERE s.number= :#{#supplier.number}")
Supplier findByNumber(@Param("supplier") Supplier supplier);

您需要为实体提供别名,如下所示:

@Query("SELECT s FROM Supplier s WHERE s.number= :#{#supplier.number}")
Supplier findByNumber(@Param("supplier") Supplier supplier);

请提供您的供应商类别代码。我相信有更好的方法可以做到这一点。请提供您的供应商类别代码。我相信有更好的办法。