when building respositories in spring, in my repository interface i extend it using the below
extends CrudRepository<EntityName, EntityType> where EntityName is the name of my Entity Class and EntityType is set to default type Long see sample code below
@Repository
public interface RoomRepository extends CrudRepository<Room, Long> {
}
I have noticed however the use of JpaRepository see example below
public interface RoomRepository extends JpaRepository<Room, UUID>{
public Boolean existsRoom(String roomNumber);
}

JpaRepository extends PagingAndSortingRepository which in turn extends CrudRepository.
Because of the inheritance mentioned above, JpaRepository will have all the functions of CrudRepository and PagingAndSortingRepository.
So if you don't need the repository to have the functions provided by JpaRepository and PagingAndSortingRepository, use CrudRepository.
Reference: https://www.javatpoint.com/spring-boot-crud-operations#:~:text=CrudRepository%20does%20not%20provide%20any,works%20as%20a%20marker%20interface.
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