Neil
06/02/2021, 3:16 PMashmelev
06/02/2021, 6:56 PMJdbcTemplate
and write prepared-statement SQL directly or create a StoredProcedure and call it from my app. That way the rows stay on the SQL instance and do not transit the networkOlek Brzozowski
06/02/2021, 9:12 PMfetch-size
property - stackoverflow thread.
I am not sure how it works for hibernate, but for jdbc it should load data in chunks 🙂
Don’t turn it into List because Stream is lazy and List isn’t. If you want to perform some logic on this stream, for example smth like this:
val users: Stream<User> = repository.users() // or even kotlin Sequence would be better
users.forEach {
// do something with user
}
the data would be loaded in chunks (as you would specify it in fetch size).
So for example, if you set fetch size to 100, you would take 100 users, perform logic in forEach
block, and then fetch another chunk of data (100users) till the end of stream (or sequence which is kotlin equivalent of lazy collection)Neil
06/02/2021, 10:01 PMJacob
06/02/2021, 10:15 PMJacob
06/02/2021, 10:21 PMashmelev
06/03/2021, 12:21 AMNot all Spring Data modules currently support Stream<T> as a return type
In the end, @Neil, if you do not need the rows in your app, then JdbcTemplate is a better solution. If you require them as a Stream (rather than List), it appears that is also possible (under certain circumstances)Neil
06/03/2021, 7:59 AM