Jira服务器插件 - Atlassian PocketKnife - QueryDSL - 使用executewithKeys()进行批量插入对ORACLE和SQL Server不起作用。

问题描述 投票:1回答:1

我试图使用QueryDSL提供的batch-Insert功能批量插入一些记录。当我只使用execute()时,同样的代码可以工作,但必须单独编写一个select查询来获取最后插入的记录。

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);

这段代码在MySQL和PostgreSQL中可以使用,但在ORACLE和SQL Server中却失败了,有什么办法可以做到这一点,并且还能得到插入记录的id。

我得到的异常如下。

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: ****该语句必须在获得任何结果之前执行****。

sql-server oracle querydsl jira-plugin atlassian-plugin-sdk
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.