I need hibernate to generate sql like this INSERT INTO table_a (a_id, a_name) VALUES (5, 'a5'),(6, 'a6');
.
With sql like that you can add 2 row with 1 statement. I can get
a_id, a_name
------------------
5 a5
6 a6
When in hibernate, when you save set of one to many relationship, hibernate will insert with multiple insert statement. This will cause if you insert 1000 row to 1 table with HQL will resulted in something like this :
INSERT INTO scoring.table_a (`a_id`, `a_name`) VALUES (1, 'a');
INSERT INTO scoring.table_a (`a_id`, `a_name`) VALUES (2, 'a');
....
...
..
INSERT INTO scoring.table_a (`a_id`, `a_name`) VALUES (1000, 'a');
And the elapsed time is :
Executed 1,000 queries; elapsed time (seconds) - Total: 0.78, SQL query: 0.78, Building output: 0
And when i test with the same values, use SQL INSERT INTO table_a (a_id, a_name) VALUES (5, 'a'),(6, 'a'),(),...,...,(1000, 'a');
will resulted in elapsed time like this :
Query 1 of 1, Rows read: 0, Elapsed time (seconds) - Total: 0.02, SQL query: 0.02, Building output: 0
The result of my test is, 1 statement of 1000 value(0.02s) will be about 39 times faster than 1000 insert statement with each have 1 value(0.78s) like hibernate do. So is there a way to make HQL that generate SQL like that for insert or maybe update also. Or this is means we must Override the hibernate dialect?
Thanks for the any hint