I was following a tutorial when building a project in Spring and the @Repository interfaces were extending an other interface JpaRepository which added functionalities to the sub interface:
@Repository("myRepository")
public interface myRepository extends JpaRepository<Name, Long> {
}
In @Service class
@Autowired
private MyRepository myrepo;
@Transactional
public Stuff save(Stuff stuff) {
return myrepo.save(stuff);
}
I want to find the actual code for the 'SAVE' method.
Have downloaded spring-data-commons-core-1.2.1.RELEASE.jar
and decompiled but could not find the implementation there.
This class extends the SimpleJpaRepository class, which is the default class that Spring uses to provide implementations for repository interfaces.
JpaRepository is particularly a JPA specific extension for Repository. It has full API CrudRepository and PagingAndSortingRepository. So, basically, Jpa Repository contains the APIs for basic CRUD operations, the APIS for pagination, and the APIs for sorting.
Default available methods CrudRepository and PagingAndSortingRepository offer default methods such as: findAll, findAllById, findById, deleteAll, deleteById, save, saveAll.
The Spring framework code is hosted on GitHub. What you are looking for is in this Repository: https://github.com/spring-projects/spring-data-jpa
One implementation is the SimpleJpaRepository: https://github.com/spring-projects/spring-data-jpa/blob/master/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With