![](/img/trans.png)
[英]Spring Data JPA findAll with table in between (PropertyReferenceException)
[英]PropertyReferenceException in spring data mongdb 2.1.0
我正在使用spring數據mongdb 2.1.0。 並具有如下所示的自定義存儲庫實現:
public class ProductItemRepositoryImpl implements ProductItemRepositoryCustom {
@Override
public List<String> getItemIdsGivenSkuOrCode(String itemIdType, String itemId) {
Query query = new Query();
query.addCriteria(Criteria.where(itemIdType).is(itemId));
return mongoTemplate
.findDistinct(query, FieldNames.PRODUCT_ITEM_ID, ProductItem.COLLECTION_NAME,
String.class);
}
}
自定義倉庫:
public interface ProductItemRepositoryCustom {
List<String> getItemIdsGivenSkuOrCode(String itemIdType, String itemId);
}
回購:
public interface ProductItemRepository
extends MongoRepository<ProductItem, Long>, ProductItemRepositoryCustom {
}
我不明白為什么它考慮將自定義方法(getItemIdsGivenSkuOrCode)作為屬性。 當我運行此命令時,出現以下給定錯誤:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productItemRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property getItemIdsGivenSku found for type ProductItem!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:740) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
我認為它必須與方法命名有關
假設您在ProductItem
中的字段是
String itemIdType;
String itemId;
方法名稱為
public interface ProductItemRepositoryCustom {
List<String> findByItemIdTypeOrItemId(String itemIdType, String itemId);
}
為了安全起見,您可以添加查詢
@Query("{ 'itemIdType': ?0, 'itemId': ?1}")
public List<String> findByItemIdTypeOrItemId(String itemIdType, String itemId);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.