Как я могу (если могу) расширить составное хранилище?

#hibernate #jpa #spring-data-jpa

#впадать в спящий режим #jpa #spring-data-jpa #спящий режим

Вопрос:

Я пытаюсь предоставить общий репозиторий Parrent для всех моих репозиториев «для каждого агрегированного корня», который я могу позже использовать полиморфно.

Я создал родительский «составленный репозиторий». Который должен быть реализован другими конкретными репозиториями.

 @Repository
public interface ZoneNameJpaRepository extends GenericJpaRepository<ZoneDTO, GenericPJM_Id> {
}
  
 public interface GenericJpaRepository<T extends GenericPJM, ID extends GenericPJM_Id>
    extends JpaRepository<T, ID>, GenericFindRepository<T, ID> {}
  
 @Repository
public interface GenericFindRepository<T extends GenericPJM, ID extends GenericPJM_Id> {
    List<T> findAll(boolean isLazySufficient) throws ClassNotFoundException;
    T find(ID id,boolean isLazySufficient) throws ClassNotFoundException;
}
  
 public class GenericFindRepositoryImpl<T extends GenericPJM, ID extends GenericPJM_Id> implements GenericFindRepository<T, ID> {

  @Autowired EntityManager entityManager;
  @Autowired DTO_NameAndClassMap dto_nameAndClassMap;

  private Class<T> genericType;

  public GenericFindRepositoryImpl() {
    genericType =
            (Class<T>) GenericTypeResolver.resolveTypeArgument(getClass(), GenericFindRepository.class);
    System.out.println("GenericFindRepositoryImpl Constructor: "   genericType.getSimpleName());
  }

  @Override
  public List<T> findAll(boolean isLazySufficient) throws ClassNotFoundException {
    if (isLazySufficient) {
      return lazyFindAll();
    } else {
      return findAll();
    }
  }

  @Override
  public T find(ID id, boolean isLazySufficient) throws ClassNotFoundException {
    if (isLazySufficient) {
      return lazyFind(id);
    } else {
      return find(id);
    }
  }

  private T find(ID id) {
    System.out.println("_________________GenericFIndRepository find_____________________");
    return entityManager.find(genericType, id);
  }

  private T lazyFind(ID id) throws ClassNotFoundException {
    EntityGraph entityGraph = entityManager.getEntityGraph("Generic_lazy_loading");
    Map hints = new HashMap();
    hints.put("javax.persistence.fetchgraph", entityGraph);
    System.out.println("_________________GenericFIndRepository find_____________________");
    return (T) entityManager.find(genericType, id, hints);
  }

  private List<T> lazyFindAll() throws ClassNotFoundException {
    EntityGraph entityGraph = entityManager.getEntityGraph("Generic_lazy_loading");
    List<T> results =
        entityManager
            .createQuery(getQueryStringToFindAll(), genericType)
            .setHint("javax.persistence.fetchgraph", entityGraph)
            .getResultList();
    System.out.println("_________________GenericFIndRepository lazyFindAll()_____________________");
    return results;
  }

  private List<T> findAll() throws ClassNotFoundException {
    EntityGraph entityGraph = entityManager.getEntityGraph("Generic_lazy_loading");
    List<T> results =
        entityManager.createQuery(getQueryStringToFindAll(), genericType).getResultList();
    System.out.println("_________________GenericFIndRepository lazyFindAll()_____________________");
    return results;
  }

  private String getEntityNameBasedOnClass(Class desiredClass) {
    // Class<?> aClass = T;
    Table table = genericType.getAnnotation(Table.class);
    String tableName = table.name();
    System.out.println("GENERIC_FIND_REPOSITORY findAllByClass() table name found: "   tableName);
    return desiredClass.getSimpleName();
  }

  private String getQueryStringToFindAll() {
    StringBuilder query = new StringBuilder();

    query.append("from "   getEntityNameBasedOnClass(genericType));
    return query.toString();
  }
}
  

Я получаю следующую ошибку:

 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'EDataFeedRestServiceImplV2': Unsatisfied dependency expressed through field 'genericDB_crud_service'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'genericDB_CRUD_ServiceImpl': Unsatisfied dependency expressed through field 'generic_crud_dao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'generic_CRUD_DaoImpl': Unsatisfied dependency expressed through field 'repositoryLookUpMap'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'repositoryLookUpMap': Unsatisfied dependency expressed through field 'zoneNameJpaRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'zoneNameJpaRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.ggktech.pjm.api.model.dto.GenericPJM com.ggktech.pjm.api.repository.repository.generics.GenericFindRepository.findCustom(com.ggktech.pjm.api.model.dto.primaryKeys.GenericPJM_Id,boolean) throws java.lang.ClassNotFoundException! No property findCustom found for type ZoneDTO!
  

Любое обходное решение или комментарий будут приняты с благодарностью

Комментарии:

1. Spring пытается автоматически сгенерировать компонент реализации для GenericFindRepository . Попробуйте аннотировать его с помощью @NoRepositoryBean .

2. @crizzis Я пробовал это. Ошибка остается той же. Я обновляю вопрос с полной ошибкой. PS: я изменил название пользовательских методов на findCustom() и findAllCustom(), пожалуйста, ПОМОГИТЕ