简体   繁体   中英

@EntityGraph annotation doesn't work properly?

I need to implement two different implementations for the same findAll() method by following different EntityGraphs annotations. By referencing through another StackOverflow post, I found a way to implement the same findAll() method with different EntityGrpahs. But when I use default methods as mentioned in that post, I am not getting the expected behavior. It neglects the @EntityGraph annotation and returns lazy Collections by following the default behavior. Please provide a fix for this issue or state any other better solution that I can implement to solve this problem.

public interface BspCategoryRepository extends JpaRepository<DbpMetaBspCategory, String> {

    @EntityGraph(attributePaths = {"dbpBspMetaCollection","dbpBspMetaCollection.dbpBspMetaCustomFieldCollection","dbpBspMetaCollection.bspType","dbpBspMetaCollection.bankCode","dbpBspMetaCollection.dbpBspMetaCustomFieldCollection.fieldType"}, type = EntityGraph.EntityGraphType.FETCH)

    default List<DbpMetaBspCategory> findAllCategories(){
      return findAll();
    }


}

Please refer to the second answer in the post which was answered by Femi. References

Spring Data simply can not know about this annotation, as the method is not abstract. You should be able to declare the method just like this:

@EntityGraph(attributePaths = {"dbpBspMetaCollection","dbpBspMetaCollection.dbpBspMetaCustomFieldCollection","dbpBspMetaCollection.bspType","dbpBspMetaCollection.bankCode","dbpBspMetaCollection.dbpBspMetaCustomFieldCollection.fieldType"}, type = EntityGraph.EntityGraphType.FETCH)
List<DbpMetaBspCategory> findAllCategories();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM