in Spring Boot and JPA there is the interface JpaRepository, which already provides the most important methods like findAll
, saveAll
. Is there also such an interface for the associated RestService?
If not, how could one proceed to define such an interface. I have looked into JpaRepository once, there the methods are not coded out. But also only with List<T> findAll();
specified, where is the actual code?
Thanks a lot
CodePudding user response:
the methods are not coded out. But also only with List findAll(); specified, where is the actual code?
JpaRepository
is just an interface meaning it provides just the declarations and signatures of what should be available from that interface.
JpaRepository
is a way from spring to take advantage of JPA layer
and provide some additional commonly used functionalities very useful to the programmer.
Having said that it is important to understand that JPA layer
follows JPA specification
, and is just that, a specification not an implementation. Multiple providers come and provide their implementation as far as they comply with this specification. Those providers (ex hibernate
, eclipseLink
, DataNucleus
) provide the functionality of JPA layer
. Those providers, provide the code to communicate with database and do the actual work of jpa layer
.
What JpaRepository
does, is that it takes advantage of this JPA layer
and provides some extra functionality by invoking what is necessary on the jpa layer
and expose some common functionalities. So JpaRepository
will not communicate directly with database using native queries but instead use the jpa layer
offered from example from hibernte
and provide some jpa query
to hibernate to retrieve what it wants.
Inside Spring you can find some implementation classes of JpaRepository
like SimpleJpaRepository.class
but again they don't provide end to end functionality but instead just communicate through jpa layer
indirectly with a provider like hibernate to provide some commonly used functionality to the programmer.