Is it possible to create read-only repositories using Spring Data?
I have some entities linked to views and some child entities for which I would like to provide a repository with some methods like findAll()
, findOne()
and some methods with the @Query
annotation. I would like to avoid providing methods like save(…)
and delete(…)
since they make no sense and could create errors.
public interface ContactRepository extends JpaRepository<ContactModel, Integer>, JpaSpecificationExecutor<ContactModel> {
List<ContactModel> findContactByAddress_CityModel_Id(Integer cityId);
List<ContactModel> findContactByAddress_CityModel_Region_Id(Integer regionId);
// ... methods using @Query
// no need to save/flush/delete
}
Thanks!