Optimize Spring-Data JPA queries

后端 未结 2 1109
花落未央
花落未央 2020-12-28 18:22

I am looking for possible optimizations for framework-generated queries. As far as I understand, the process is the following:

  • you could declare your domain

相关标签:
2条回答
  • 2020-12-28 19:13

    Take a look at JPA's lazy fetching strategy. It will allow you to select objects without their relations, but will fetch the relations when you reference them.

    0 讨论(0)
  • 2020-12-28 19:16

    One solution is to use DTO's:

    @Query("select new FilteredOrder(o.name, o.size, o.cost) from Order o where o.id = ?1")
    Page<FilteredOrder> findFilteredOrderById(Pageable pageable, String id);
    

    If you want to have entities for some reports generation maybe you should think about using nosql datastore?

    0 讨论(0)
提交回复
热议问题