我想向<T> T findOrCreate(Supplier<Optional<T>> finder, Supplier<T> factory)
我所有的存储库介绍一个。于是新建了一个界面
@NoRepositoryBean
public interface ExtendedJpaRepository<T, ID extends Serializable> extends JpaRepository<T, ID> {
T findOrCreate(Supplier<Optional<T>> finder, Supplier<T> factory);
}
.
public class ExtendedJpaRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements ExtendedJpaRepository<T, ID> {
private final JpaEntityInformation entityInformation;
private final EntityManager entityManager;
public ExtendedJpaRepositoryImpl(JpaEntityInformation entityInformation, EntityManager entityManager) {
super(entityInformation, entityManager);
this.entityInformation = entityInformation;
this.entityManager = entityManager;
}
@Override
public T findOrCreate(Supplier<Optional<T>> finder, Supplier<T> factory) {
throw new NotImplementedException("No implemented yet");
}
}
然后我在我的具体存储库中使用这个接口,例如RecipeIngredientRepository:
public interface RecipeIngredientRepository extends ExtendedJpaRepository<RecipeIngredient, Long> {}
当我最终将存储库注入我的服务时,我得到以下异常:
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'recipeIngredientRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property find found for type RecipeIngredient! Did you mean 'id'?
它正在我的实体中搜索find
属性RecipeIngredient
。我不希望它这样做。我认为这与JPA Query Methods有关。所以我将名称从findOrCreate
更改xxx
为绕过任何查询方法检测 - 没有成功。然后它会搜索一个xxx
属性。
是什么让 spring data 寻找这个属性?我正在使用org.springframework.boot:spring-boot-starter-data-jpa
.