我有一种情况,我的数据库中有一个层次结构,如下所示: +-------+ | Foo | +-------+ | Id | | Type | | Color | +-------++------------+ +------------+| A | | B |+------------+ +------------+| FooId | | FooId || Status | | Connection || SourceType | | Comments |+------------+ +------------+现在这是我的 Java 实体:@Entity@Table(name = "Foo", schema = "dbo")@Inheritance(strategy = InheritanceType.JOINED)public abstract class Foo { /* fields, getters, setters, constructors */}@Entity@Table(name = "A", schema = "dbo")@PrimaryKeyJoinColumn(name = "FooId")public class A extends Foo { /* fields, getters, setters, constructors */}@Entity@Table(name = "B", schema = "dbo")@PrimaryKeyJoinColumn(name = "FooId")public class B extends Foo { /* fields, getters, setters, constructors */}然后我有我按照本指南开发的存储库:@NoRepositoryBeanpublic interface FooBaseRepository<T extends Foo> extends Repository<T, Integer> {}public interface FooRepository extends FooBaseRepository<Foo>, JpaRepository<Foo, Integer> {}public interface ARepository extends FooBaseRepository<A>, JpaRepository<A, Integer> {}public interface BRepository extends FooBaseRepository<B>, JpaRepository<B, Integer> {}我已经让这一切正常工作没问题。但是在进一步检查这个架构后,我想知道为什么我什至需要FooBaseRepository. 它在文章和 spring 指南中说要为“只读”操作定义一个基本存储库,但是当有人可以使用它FooRepository来执行读/写操作时,经历创建这个基本只读存储库的麻烦有什么意义?似乎这种情况只需要以下回购:public interface FooRepository extends JpaRepository<Foo, Integer> {}public interface ARepository extends JpaRepository<A, Integer> {}public interface BRepository extends JpaRepository<B, Integer> {}一切都会好起来的。我在这里缺少什么?
添加回答
举报
0/150
提交
取消