Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JpaRepository interface implementation, I want to understand where are its methods implemented? [duplicate]

Tags:

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.

like image 735
Mandy Avatar asked Dec 01 '16 13:12

Mandy


People also ask

Which is the default implementation class of the JpaRepository interface?

This class extends the SimpleJpaRepository class, which is the default class that Spring uses to provide implementations for repository interfaces.

What is JpaRepository interface?

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.

What are the default methods in JPA repository?

Default available methods CrudRepository and PagingAndSortingRepository offer default methods such as: findAll, findAllById, findById, deleteAll, deleteById, save, saveAll.


1 Answers

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

like image 188
Simon Martinelli Avatar answered Sep 26 '22 16:09

Simon Martinelli