i want to select data from table users by inner join table users_role inner join table role with where clause but when i build the app an error accured
@Query(value = "select u from users u join users_role ur on u.id = ur.user_id join roles r on ur.role_id = r.id where r.role = 'ROLE_PL' ")
List<User> findPersonels();
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 8.287 s <<< FAILURE! - in com.backend.AuthentificationJwtApplicationTests
[ERROR] contextLoads(com.backend.AuthentificationJwtApplicationTests) Time elapsed: 0.004 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'personnelController': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personnelRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.backend.repository.PersonnelRepository.findPersonels()!
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personnelRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.backend.repository.PersonnelRepository.findPersonels()!
Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.backend.repository.PersonnelRepository.findPersonels()!
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: users is not mapped [select u from users u join users_role ur on u.id = ur.user_id join roles r on ur.role_id = r.id where r.role = 'ROLE_PL' ]
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: users is not mapped [select u from users u join users_role ur on u.id = ur.user_id join roles r on ur.role_id = r.id where r.role = 'ROLE_PL' ]
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: users is not mapped
Your query seems to be neither JPQL ( users
isn't an entity) nor SQL (you can't select <table alias> from ...
in SQL).
Pick one of the two and if you pick SQL add a nativeQuery=true
to the @Query
annotation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.