Do you think it is possible to use hibernate to insert 0.11 million data entries in 5 seconds?

Source: Internet
Author: User

The requirement is that you need to query the data of several tables and then insert them to another table.

As soon as you see the requirement, many people will use hibernate to query the data and put it in the list,

Then, we use a for loop to traverse the object, assign values to the object After retrieving data one by one, and then call the Save method on the DaO layer to save the object.

Hibernate saves a piece of data in about 35 milliseconds. Let's calculate the time:

35*110000 = 3850000 milliseconds

3850000/1000 = 3850 seconds

3850/60 = 64.1666666 minutes,

If we use hibernate, We need to execute it for more than an hour, which cannot reflect the efficiency at all. Moreover, the pressure on the server is not small due to such a large amount of data.

Well, we have said so much above. Let's take a look at the actual operations.

The tested database is MSSQL, And the MySQL speed is similar.

I have created a table with 115546 data records. 0.11 million

Then I created another table with a completely different structure.

Here, I directly use SQL statements to insert data and check the Code:

Insert into test (name) Select S. Address from student s

Using the insert into SELECT statement is actually equivalent to copying.

At this time, we can use hibernate to create a query and execute a modified SQL statement.

This is very efficient. It takes only five seconds for me to insert 0.11 million pieces of data. The preceding method takes more than one hour.

:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.