Entradas

Mostrando entradas de junio, 2023

SpringBoot (7) Spring Data JPA (2). Creating a custon Repository for several Entities

0. Introduction When a lot of entities are used, many operations in a repository are the same and a lot of boilerplate code is produced. This idea of using a Repository for many entities has been rated as heretical for the Spring philosophy. But for the sake of simplicity, I'll be using an interface and a class implementing this interface for a reusable Repository. 1. The IBaseRepositoryInterface Here is the interface: package ximo . repositories ; import java . util . List ; import jakarta . transaction . Transactional ; import ximo . xotherapps . model . base . Base ; public interface IBaseRepository { public < S extends Base > S findEdu ( Class < S > clazz , long id ) ; public < S extends Base > S findByDescriptionEdu ( Class < S > clazz , String description ) ; @Transactional public void insertEdu ( Base entity ) ; @Transactional public Base updateEdu ( Base enti