pkainulainen/spring-data-jpa-examples

How to used repository classes for same method twice

Opened this issue · 1 comments

Lets say I've following method. Supposed I may have many record for single UserId?

public interface StudentRepository extends CrudRepository<Student, String> {   
   List<Student> findByStudentId(String StudentId); // used generic purposes
   List<Student> findByStudentId(String StudentId); // for getting last updated record for this StudentId
}

You cannot use the same method for this purpose because it doesn't compile. However, you can create two different methods and create the database query by using the Query annotation (or query generation from method strategy).