Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Spring Data

You're reading from   Spring Data Want to make it easier to implement data access with your Spring-powered applications? Then this is the book you need. A complete tutorial to Spring Data, it makes learning easier with lots of code examples and clear instructions.

Arrow left icon
Product type Paperback
Published in Nov 2012
Publisher Packt
ISBN-13 9781849519045
Length 160 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Petri Kainulainen Petri Kainulainen
Author Profile Icon Petri Kainulainen
Petri Kainulainen
Arrow right icon
View More author details
Toc

Adding custom functionality to all repositories


Sometimes we have to add custom functionality to all repositories. In this section, we will learn how we can do this and create a custom repository method that is used to delete an entity by using its ID.

We can add custom functionality to all repositories by following these steps:

  1. Create a base interface that declares the custom methods.

  2. Implement the created interface.

  3. Create a repository factory bean.

  4. Configure Spring Data JPA to use our repository factory bean.

  5. Create a repository interface.

  6. Implement a service class that uses the custom functionality.

Creating the base repository interface

We start by creating a base repository interface that declares the methods that are available in the actual repositories. We can do this by:

  1. Creating an interface that takes the type of the managed entity and the type of its ID as a type parameter.

  2. Extending both the JpaRepository<T, ID> and QueryDslPredicateExecutor<T> interfaces in our base repository...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image