<i id='Ii7ed'><tr id='Ii7ed'><dt id='Ii7ed'><q id='Ii7ed'><span id='Ii7ed'><b id='Ii7ed'><form id='Ii7ed'><ins id='Ii7ed'></ins><ul id='Ii7ed'></ul><sub id='Ii7ed'></sub></form><legend id='Ii7ed'></legend><bdo id='Ii7ed'><pre id='Ii7ed'><center id='Ii7ed'></center></pre></bdo></b><th id='Ii7ed'></th></span></q></dt></tr></i><div id='Ii7ed'><tfoot id='Ii7ed'></tfoot><dl id='Ii7ed'><fieldset id='Ii7ed'></fieldset></dl></div>

      <bdo id='Ii7ed'></bdo><ul id='Ii7ed'></ul>
  1. <tfoot id='Ii7ed'></tfoot>

    1. <small id='Ii7ed'></small><noframes id='Ii7ed'>

      <legend id='Ii7ed'><style id='Ii7ed'><dir id='Ii7ed'><q id='Ii7ed'></q></dir></style></legend>

    2. 您是否应该在 JPA 中的每个表都有一个存储库?

      时间:2024-08-24
        1. <legend id='XRUJo'><style id='XRUJo'><dir id='XRUJo'><q id='XRUJo'></q></dir></style></legend>

          <small id='XRUJo'></small><noframes id='XRUJo'>

          • <bdo id='XRUJo'></bdo><ul id='XRUJo'></ul>
              <tbody id='XRUJo'></tbody>

          • <i id='XRUJo'><tr id='XRUJo'><dt id='XRUJo'><q id='XRUJo'><span id='XRUJo'><b id='XRUJo'><form id='XRUJo'><ins id='XRUJo'></ins><ul id='XRUJo'></ul><sub id='XRUJo'></sub></form><legend id='XRUJo'></legend><bdo id='XRUJo'><pre id='XRUJo'><center id='XRUJo'></center></pre></bdo></b><th id='XRUJo'></th></span></q></dt></tr></i><div id='XRUJo'><tfoot id='XRUJo'></tfoot><dl id='XRUJo'><fieldset id='XRUJo'></fieldset></dl></div>
                <tfoot id='XRUJo'></tfoot>
                本文介绍了您是否应该在 JPA 中的每个表都有一个存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                您是否应该在 JPA 中为每个表创建一个存储库?如果不是,如何解析存储库数据库中的泛型?

                Are you supposed to have one repository per table in JPA? If not, how do you resolve the generics in the repository database?

                例如,下面是一个 StoreRepository.它处理 Store 对象上的 CRUD 操作.如果我希望存储库也保存 StoreEvent 对象,我将如何更改下面的接口以容纳这两个对象?

                For example, below is a StoreRepository. It handles CRUD operations on the Store object. If I wanted the repository to save a StoreEvent object as well, how would I go about changing the interface below to accommodate both objects?

                @Repository
                public interface StoreRepository extends JpaRepository<Store, String> {
                    public Store findByGuid(String guid);
                }
                

                推荐答案

                作为存储库是一个源自 Domain 的概念驱动设计,考虑数据库表是错误的方法.根据定义,您可以从存储库访问聚合根.实际上,存储库正在模拟这些的集合.

                As repository is a concept derived from Domain Driven Design, thinking about database tables is the wrong approach. By definition you access aggregate roots from a repository. Effectively a repository is simulating a collection of these.

                现在什么形成聚合根?可能更有趣:什么不是?当然,这高度依赖于您的域,但让我在这里举个例子.包含 LineItemsOrder 通常被建模为聚合根.这是由于 Order 的组合性质造成的.如果没有周围的 Order,则 LineItem 将不存在.

                Now what forms an aggregate root? Probably even more interesting: what does not? That's, of course, highly dependent on your domain, but let me give you an example here. An Order containing LineItems usually is modeled as an aggregate root. This is due to the composition nature of the Order. A LineItem would not exist without a surrounding Order.

                通常持久性访问机制应该遵循领域原则.因此,您可以将 OrderLineItem 建模为 @Entity 类,但只创建一个 OrderRepository,因为它们形成聚合根,有效控制对象图中的一致性规则.

                Usually the persistence access mechanisms should follow the domain principles. Thus, you'd model both Order and LineItem as @Entity classes but only create an OrderRepository, as they form the aggregate root and effectively control the consistency rules within the object graph.

                我们还强烈建议不要使用商店特定的存储库基础接口,因为它们 - 顾名思义 - 公开商店细节(例如 flush()) 发送给他们不应该知道的客户,如果可能的话.在我的回答此处中了解更多信息.

                We also strongly recommend not to use the store specific repository base interfaces as they - as the name suggests - expose store specifics (e.g. flush()) to the clients of which they shouldn't be aware, if possible. Read more on that in my answer here.

                这篇关于您是否应该在 JPA 中的每个表都有一个存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何将 @Transactional 与 Spring Data 一起使用? 下一篇:为什么在 Spring Data JPA Repository 上的 save() 之后使用返回的实例?

                相关文章

              1. <small id='KRMNZ'></small><noframes id='KRMNZ'>

                <i id='KRMNZ'><tr id='KRMNZ'><dt id='KRMNZ'><q id='KRMNZ'><span id='KRMNZ'><b id='KRMNZ'><form id='KRMNZ'><ins id='KRMNZ'></ins><ul id='KRMNZ'></ul><sub id='KRMNZ'></sub></form><legend id='KRMNZ'></legend><bdo id='KRMNZ'><pre id='KRMNZ'><center id='KRMNZ'></center></pre></bdo></b><th id='KRMNZ'></th></span></q></dt></tr></i><div id='KRMNZ'><tfoot id='KRMNZ'></tfoot><dl id='KRMNZ'><fieldset id='KRMNZ'></fieldset></dl></div>

                • <bdo id='KRMNZ'></bdo><ul id='KRMNZ'></ul>

              2. <legend id='KRMNZ'><style id='KRMNZ'><dir id='KRMNZ'><q id='KRMNZ'></q></dir></style></legend>

                1. <tfoot id='KRMNZ'></tfoot>