0
import org.springframework.stereotype.Repository;

@Repository
public interface CustomRepository extends JpaRepository<Object, Long> {

     @Query(value = "SELECT name FROM student", nativeQuery = true)
    List<String> getAllStudentNames();
}

Will this work if not what will be the solution for this? I don't want to create student Entity.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302

1 Answers1

0

If you do not have a Student class then you should not make a JpaRepository for it. This is my suggestion:

@Repository
public class StudentRepository {
    @PersistenceContext
    private EntityManager em;

    public List<String> findAllStudentNames() {
        return em.createNativeQuery("SELECT name FROM student").getResultList();
    }
}
Calabacin
  • 725
  • 2
  • 8
  • 19