Как сформировать и запустить hql запрос?

При запуске приложения получаю ошибку:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-12 13:33:57.075 ERROR 5748 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mainController': Unsatisfied dependency expressed through field 'oOrderChangeFIOService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'OOrderChangeServiceImpl': Unsatisfied dependency expressed through method 'setoOrderChangeFIORepository' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'OOrderChangeFIORepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.github.steed777.repository.OOrderChangeFIORepository.findByOOrderChangeFIO()!
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]

Вот репозиторий и и сущность:

@Transactional
public interface OOrderChangeFIORepository extends JpaRepository<OOrderChangeFIO, Integer> {
    List<OOrderChangeFIO> findAll();

    /*sql запрос
    select a.id, b.lawyer_id, a.new_fio, c.person_full_name as old_fio, c.doc_date_number as order_name
    from o_order_change_fio a, lawyer_doc b, common_base_doc c where a.id = c.id and c.lawyer_id = b.lawyer_id and
    not exists(select * from lawyers where b.lawyer_id = lawyers.id and lawyer_status = 5);*/



  @Query("select l from Lawyers l where Lawyers.id = l.id and not exists (select lawyer_status from lawyers where lawyer_status =: status5)")
    List<OOrderChangeFIO>  findByOOrderChangeFIO();
}

@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
@Entity
@Table(name = "LAWYERS")
public class OOrderChangeFIO {
    public OOrderChangeFIO() {
    }

    @Formula("select id from o_order_change_fio, common_base_doc where id = common_base_doc.id")
    private Long id;
    @Formula("select fd.lawyer_id from lawyer_doc, common_base_doc where fd.lawyer_id = common_base_doc.lawyer_id")
    private Long lawyer_id;
    @Formula("select new_fio from o_order_change_fio, common_base_doc where o_order_change_fio.id = common_base_doc.id")
    private String new_fio;
    @Formula("select person_full_name from o_order_change_fio, common_base_doc where o_order_change_fio.id = common_base_doc.id")
    private String person_full_name;
    @Formula("select doc_date_number from o_order_change_fio, common_base_doc where o_order_change_fio.id = common_base_doc.id")
    private String doc_date_number;
    @Id
    @Column(name = "lawyer_status", insertable = false, updatable = false)
    private Integer lawyer_status;


Ответы (1 шт):

Автор решения: Konstantin

Приложение не запускалось из-за неправильно сформированного hql запроса. Вот как должен выглядеть запрос:

@Query("select distinct ls from OOrderChangeFIO ls where not exists (select l from OOrderChangeFIO l where ls.id = l.id and l.lawyer_status = 5)")

→ Ссылка