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.
: