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

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

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

        Spring Data JDBC - 多对一关系

        时间:2023-09-30
        <i id='iNtI4'><tr id='iNtI4'><dt id='iNtI4'><q id='iNtI4'><span id='iNtI4'><b id='iNtI4'><form id='iNtI4'><ins id='iNtI4'></ins><ul id='iNtI4'></ul><sub id='iNtI4'></sub></form><legend id='iNtI4'></legend><bdo id='iNtI4'><pre id='iNtI4'><center id='iNtI4'></center></pre></bdo></b><th id='iNtI4'></th></span></q></dt></tr></i><div id='iNtI4'><tfoot id='iNtI4'></tfoot><dl id='iNtI4'><fieldset id='iNtI4'></fieldset></dl></div>

          <legend id='iNtI4'><style id='iNtI4'><dir id='iNtI4'><q id='iNtI4'></q></dir></style></legend>
          <tfoot id='iNtI4'></tfoot>

                <bdo id='iNtI4'></bdo><ul id='iNtI4'></ul>

              • <small id='iNtI4'></small><noframes id='iNtI4'>

                  <tbody id='iNtI4'></tbody>
                1. 本文介绍了Spring Data JDBC - 多对一关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我似乎在网上找不到任何关于在 Spring JDBC 中使用多对一映射的参考资料.我刚刚在不支持的文档中看到了,但我不确定是否是这种情况.

                  I can't seem to find any reference online with regards to using a Many-To-One mapping in Spring JDBC. I just saw in the documentation that is not supported but I'm not sure if this is the case.

                  我的示例是我想将我的 AppUser 映射到特定部门.

                  My example is that I want to map my AppUser to a particular Department.

                  作为参考,AppUser 使用 DEPARTMENT_ID 加入 Department 表

                  For reference, AppUser joins to Department table using DEPARTMENT_ID

                  @Table(value="m_appuser")
                  public class AppUserProjectionTwo {
                      @Id
                      private Long id;
                      private String firstname;
                      private String middlename;
                      private String lastname;
                  
                  
                  
                      @Column("DEPARTMENT_ID")
                      private DepartmentProjection departmenProjection;
                  
                      public Long getId() {
                          return id;
                      }
                  
                      public void setId(Long id) {
                          this.id = id;
                      }
                  
                  

                  但是,它似乎无法正确映射.

                  However, it seems that it won't map properly.

                  @Table("M_DEPARTMENT")
                  public class DepartmentProjection {
                      @Id
                      private Long id;
                  
                      public Long getId() {
                          return id;
                      }
                  
                      public void setId(Long id) {
                          this.id = id;
                      }
                  

                  创建的查询如下所示.我正在寻找更多相反的东西,其中 M_APPUSER.department_ID = Department.id

                  The created query looks like this. I was looking for something more of the opposite in which M_APPUSER.department_ID = Department.id

                  [SELECT "m_appuser"."ID" AS "ID", "m_appuser"."LASTNAME" AS "LASTNAME", "m_appuser"."FIRSTNAME" AS "FIRSTNAME", "m_appuser"."MIDDLENAME" AS "MIDDLENAME", "departmenProjection"."ID" AS "DEPARTMENPROJECTION_ID" FROM "m_appuser" LEFT OUTER JOIN "M_DEPARTMENT" AS "departmenProjection" ON "departmenProjection"."DEPARTMENT_ID" = "m_appuser"."ID" WHERE "m_appuser"."FIRSTNAME" = ?];
                  

                  谢谢

                  推荐答案

                  我刚刚在文档中看到不支持,但我不确定是否是这种情况.

                  I just saw in the documentation that is not supported but I'm not sure if this is the case.

                  我可以确认它不受支持.多对一关系跨越聚合的边界.跨聚合的引用必须建模为被引用聚合的 id.

                  I can confirm it is not supported. Many-To-One relationships cross the boundaries of aggregates. References across aggregates must be modelled as ids of the referenced aggregate.

                  如果你不这样做,Spring Data JDBC 将把引用视为一对一关系和同一聚合的一部分,这将对多对一关系产生你不想要的影响,例如当被引用的实体被删除时,被引用的实体被删除.这对于同一聚合中的一对一关系是正确的.

                  If you don't do this Spring Data JDBC will consider the reference a One-To-One relationship and part of the same aggregate which will have effects you don't want for a Many-To-One relationship, like the referenced entity getting deleted when the referenced entity gets deleted. Which would be correct for a One-To-One relationship within the same aggregate.

                  这在 中有更详细的解释https://spring.io/blog/2018/09/24/spring-data-jdbc-references-and-aggregates

                  这篇关于Spring Data JDBC - 多对一关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:DB2 System Runtime Table 检索最后执行的 SQL 语句 下一篇:Java中带有命名空间的XPath

                  相关文章

                  最新文章

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

                    <tfoot id='gKnlx'></tfoot>
                      <bdo id='gKnlx'></bdo><ul id='gKnlx'></ul>

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

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