I tried nativeQuery method for fetching some data without using JPQL in my repository file using Spring Boot, Spring Data JPA method, I am adding my sample code below:
public interface UsersRepository extends CrudRepository<Users, Long> {
@Query(value = "select u.username from users u",nativeQuery=true)
List<Users> findByUsername();
},
And calling the method by,
UsersRepository userRepo;
return (List<Users>) userRepo.findByUsername();
Then the error I am getting:
"There was an unexpected error (type=Internal Server Error, status=500). could not execute query; SQL [select u.username from users u]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query".
Can anyone help to solve this issue?