как преобразовать запрос гибернации в критерии - PullRequest
0 голосов
/ 12 февраля 2019

Я уже написал запрос, проходящий через несколько объектов, и хочу преобразовать его в отдельный критерий запроса.Не уверен, как это сделать для нескольких таблиц

StringBuilder queryString = new StringBuilder("from ");
    queryString.append(Entity).append(" e where e.specificationId in (:ids) 
       and not exists ( select 1 from Association a where "
           + "a.sourceReference = e.reference )").append("order by    
                e.displayOrder");

1 Ответ

0 голосов
/ 12 февраля 2019

Вы можете использовать Spring JPA.

@NoRepositoryBean
public interface GenericRepository<T extends Content<T>> extends JpaRepository<T, Long>

@Query("select e from #{#entityName} e where e.specificationId in (?) and not exists ( select 1 from Association a where a.sourceReference = e.reference ) order by e.displayOrder", nativeQuery=true)
public void T findByIds(List<Long> ids);

Вы создадите один интерфейс для каждого типа и реализует GenericRepository.

Пример:

@Repository
public interface AbcRepository extends GenericRepository<Abc>{

}

См .: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/

...