Is there equivalent of @BatchSize in spring-data-jdbc

问题: Hi I used spring data to map my Entity and Repository. The mapping is very simple: public class Car { Set<Part> parts; } public class Part { } I use the f...

问题:

Hi I used spring data to map my Entity and Repository. The mapping is very simple:

public class Car {

   Set<Part> parts;
}

public class Part {

} 

I use the findAllByIds(Iterable) interface of my spring data repository. And it generates a nice sql in the form of:

select from CAR where id in (?, ?, ?, ?)

for each Car it executes exactly one SQL.

Select from Part where car_id = ?

My problem starts when the related parts are fetch. It apears that it is fetching them one by one. Is there in spring data jdbc something equivalent to the batch fetching in hibernate ?

If the anser is negative is there some relatively easy way to implement it ?


回答1:

Unfortunately, the answer is short answer is "No" to both questions right now.

If you want to implement batching for selects what you would need to do is to come up with

a) a new implementation of the DataAccessStrategy which essentially implements all the CRUD functionality, and/or

b) a new EntityRowMapper which converts ResultSet rows into entities.

The first one is needed if you want to execute a different SQL statement to start with. The second one if you consider changing subsequent SQL sufficient.

There are issues around batching that you might want to track or if the exact variant you are looking for doesn't exist, feel free to create another one.

  • 发表于 2019-03-27 02:50
  • 阅读 ( 173 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除