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

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

      <tfoot id='Ujwek'></tfoot>

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

      2. 如何在 spring-data 中强制使用 CrudRepository 进行预加载?

        时间:2024-08-23
      3. <tfoot id='VylsD'></tfoot>
          <tbody id='VylsD'></tbody>
        <legend id='VylsD'><style id='VylsD'><dir id='VylsD'><q id='VylsD'></q></dir></style></legend>

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

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

                • 本文介绍了如何在 spring-data 中强制使用 CrudRepository 进行预加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个包含 List 的实体,因此默认加载 lazy:

                  I have an entity containing a List that is thus lazy loaded by default:

                  interface MyEntityRepository extends CrudRepository<MyEntity, Long> {
                  
                  }
                  
                  @Entity
                  public class MyEntity {
                      @Id
                      private Long id;
                  
                      @OneToMany(mappedBy = "bar") //lazy by default
                      private List<Bar> bars;
                  }
                  
                  @Entity
                  public class Bar {
                      //some more
                  }
                  

                  问题:如何在执行 repository.findOne(id) 时强制预先加载?

                  Question: How can I force eager loading when executing repository.findOne(id)?

                  推荐答案

                  我也需要这个,因为我在一个事务内的服务对象中调用 dao,所以我调用了 get 方法,所以没有例外,我是能够获取记录.类似于 java 8 中的东西:

                  I needed this too and as I'm calling the dao inside a service object that is insise a transaction I call call the get method so no exception and I was able to fetch the records. Something like in java 8:

                  public ProductEntity findProduct(int id) {
                      ProductEntity p = productRepository.findOne(id);
                      p.getPresentations().stream().count();
                      return p;
                  }
                  

                  p.getPresentations().stream().count(); 将强制提取,我知道这不是一个干净的方法,但它可以同时完成工作

                  p.getPresentations().stream().count(); will force the fetch, I know is not a clean way to do it but it gets the job done in the mean time

                  这篇关于如何在 spring-data 中强制使用 CrudRepository 进行预加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:@Document 注释中的 MongoDB 和 SpEL 表达式 下一篇:Spring 数据存储库将 null 作为 bytea 发送到 PostgreSQL 数据库

                  相关文章

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

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

                  1. <legend id='c2CKU'><style id='c2CKU'><dir id='c2CKU'><q id='c2CKU'></q></dir></style></legend>
                  2. <tfoot id='c2CKU'></tfoot>