Efficiency analysis of batch deletion of hibernate

xiaoxiao2021-03-06  125

Author: robbinHibernate as ORM, there is an ORM inherent problem is due to permanent synchronization can not use bulk delete and update sql batch object, only in accordance with a section of the main keys to operate. Therefore, the efficiency is relatively low relative to JDBC. However, things are not always so desperate, as long as you optimize Hibernate, you can also get quite satisfactory speed.

Java code:

1 session.

Delete

("from cat as c where ..."

);

This statement actually sends SQL:

Java code:

1 ==> SELECT ID, NAME, SEX, Weight from cat;

2 ==> DELETE from cat where id =?

Hibernate first querying the data, does consume some time, but SELECT read-only operations and INSERT, DELETE, UPDATE These database modifications have more than one order level gap on the speed. Therefore, although Hibernate is more consumed, it is not a lot of impact, mainly in memory consumption. DELETE's speed, we know that Hibernate's Batch Size can provide greatly improve INSERT, DELETE, and UPDATE. My test: Oracle817, ojdbc14.jar table record 10,000, all deleted. JDBC: SQL statement

Java code:

1 delete from cat

Speed: Average 6S Hibernate:

Java code:

1 session.

Delete

("from cat as c"

);

Batch size = 0 speed: 25s Batch size = 50 Speed: 6S Batch Delete and Batch Update Recommended JDBC, this is a principle, of course, sometimes you may have to use Hibernate to batch update and batch deletion, then I want to say at this time. That is, hibernate is quantified and deleted efficiency is not the legendary, as long as the optimization is good, the speed is very fast. Ezerg Programming

转载请注明原文地址:https://www.9cbs.com/read-99765.html

New Post(0)