How to force eager loading with CrudRepository in spring-data?

前端 未结 4 1960
抹茶落季
抹茶落季 2021-01-11 10:43

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

interface MyEntityRepository extends CrudRepository

        
4条回答
  •  一生所求
    2021-01-11 11:44

    You can force eager fetch writing custom HQL query with left join fetch, eg:

    interface MyEntityRepository extends CrudRepository {
        @Query("select e from MyEntity e left join fetch e.bar b where e.id = ?1")
        MyEntity findOne(long id)
    }
    

提交回复
热议问题