I am trying to batch insert some records using the batch-Insert functionality provided by QueryDSL. The same piece of code works when I use just execute() but then have to separately write a select query to get the last inserted records.
databaseAccessor.runInNewTransaction(databaseConnection -> {
SQLInsertClause batchInsert = databaseConnection.insert(TEST);
for (int i = 0; i < 5; i++) {
batchInsert.set(TEST.NAME, "label" + i).set(TEST.PROJECT_ID, 1).addBatch();
}
return batchInsert.executeWithKeys(TEST.ID);
}, OnRollback.NOOP);
This piece of code works for MySQL and PostgreSQL but fails for ORACLE and SQL Server, Is there a way I can do this and also get the id of the inserted records.
The exception I get is as follows:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: ****The statement must be executed before any results can be obtained.****