开发者

Loading million rows in hibernate

开发者 https://www.devze.com 2023-01-17 23:41 出处:网络
If I want 开发者_运维百科to fetch million rows in hibernate, how would it work? Will hibernate crash? How can I optimize that.typically you wouldn\'t use hibernate for this.If you need to do a batch o

If I want 开发者_运维百科to fetch million rows in hibernate, how would it work? Will hibernate crash? How can I optimize that.


typically you wouldn't use hibernate for this. If you need to do a batch operation, use sql or the hibernate wrappers for batch operations. There is no way loading millions of records is going to end well for your application. Your app with thrash as the gc runs, or possibly crash. there has to be another option.


If you read one/write one it will probably work fine. Are you sure this the way you want to read 1,000,000 rows? It will likely take a while.

If you want all the objects to be in memory at the same time, you might well be challenged.

You can optimize it best, probably, by finding a different way. For example, you can dump from the database using database tools much more quickly than reading with hibernate.

You can select sums, maxes, and counts in the database without returning a million rows over the network.

What are you trying to accomplish, exactly?


For this you would be better off using spring's jdbc tools with a row handler. It will run the query and then perform some action on a row at a time.


Bring only the columns you need. Try it out in a test environment.


You should try looking at the StatelessSession interface and example of which can be found here:

http://mrmcgeek.blogspot.com/2010/09/bulk-data-loading-with-hibernate.html

0

精彩评论

暂无评论...
验证码 换一张
取 消