How to create a custom repository in Spring Data JPA?

Spring Data JPA is great for abstracting away boilerplate code when accessing the database. It allows us to create query methods by simply defining method signatures. But sometimes, we need more complex or dynamic queries — and that’s where custom repositories come into play. In this post, I’ll show how to create a custom repository…

Read More

What is Spring Data JPA?

Spring Data JPA is a module of Spring Data that simplifies the implementation of repositories. It provides an automatic way to create repository implementations based on Java interfaces, eliminating the need to manually write the repository implementation. To make this work, you need to create an interface using the @Repository annotation and extend JpaRepository. The…

Read More
Java

How to avoid NullPointerException in Java using Optional?

Optional was introduced in Java 8 as a way to handle potentially null values more safely and expressively. It helps to avoid NullPointerException and makes the code more readable. Hands on Creating an Optional Optional can be created in several ways: Printing the results will show the following output. Checking for Value Presence Optional provides…

Read More