简体   繁体   中英

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 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 ?

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.

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