【发布时间】:2012-06-21 20:33:21
【问题描述】:
是否可以使用 Spring Data 创建只读存储库?
我有一些链接到视图的实体和一些子实体,我想为它们提供一个存储库,其中包含一些方法,如 findAll()、findOne() 和一些带有 @Queryannotation 的方法。我想避免提供像 save(…) 和 delete(…) 这样的方法,因为它们没有意义并且可能会产生错误。
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
}
谢谢!
【问题讨论】:
标签: java spring jpa spring-data spring-data-jpa