Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract med.voll.api.domain.medico.Medico med.voll.api.domain.medico.MedicoRepository.escolherMedicoAleatorioLivreNaData(med.voll.api.domain.medico.Especialidade,java.time.LocalDateTime) at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:100) ~[spring-data-jpa-3.1.0.jar:3.1.0] at org.springframework.data.jpa.repository.query.SimpleJpaQuery.(SimpleJpaQuery.java:70) ~[spring-data-jpa-3.1.0.jar:3.1.0] at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:60) ~[spring-data-jpa-3.1.0.jar:3.1.0] at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:170) ~[spring-data-jpa-3.1.0.jar:3.1.0] at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:252) ~[spring-data-jpa-3.1.0.jar:3.1.0] at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:95) ~[spring-data-jpa-3.1.0.jar:3.1.0] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:111) ~[spring-data-commons-3.1.0.jar:3.1.0] ... 59 common frames omitted Caused by: java.lang.IllegalArgumentException: org.hibernate.query.sqm.InterpretationException: Error interpreting query [ select m from Medico m where m.ativo = 1 and m.especialidade = :especialidade and m.id not in( select c.medico.id from Consulta c where c.data = :data ) order by rand() limit 1 ]; this may indicate a semantic (user query) problem or a bug in the parser [ select m from Medico m where m.ativo = 1 and m.especialidade = :especialidade and m.id not in( select c.medico.id from Consulta c where c.data = :data ) order by rand() limit 1 ]