Spring JPA: Under the covers

Spring Data JPA

public interface FooRepository extends JpaRepository<Foo, Long> { 
}

But how does Spring JPA work!

1. Automatic Custom Queries:

public interface FooRepository extends JpaRepository<Foo, Long> {     public Optional<Foo> findByName(String name); }
public interface FooRepository extends JpaRepository<Foo, Long> {     public Optional<Foo> findByFirstnameAndLastname(String firstname, String lastname);     public List<Foo> findByFirstnameOrLastname(String firstname, String lastname);    public List<Foo> findDistinctByLastname(String lastname);
}

2. Manual custom Queries

public interface FooRepository extends JpaRepository<Foo, Long> {     @Query("SELECT f FROM Foo f WHERE LOWER(f.name) = LOWER(:name)")
Foo retrieveByName(@Param("name") String name);
}

Conclusion

Full stack Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store