this is my configuration ffiles
spring:
datasource:
url: jdbc:mysql://localhost:3306/study?useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true
hikari:
auto-commit: false
username: root
password: asdfjj
jpa:
generate-ddl: false
properties:
hibernate:
jdbc:
batch_size: 100
order_inserts: true
this is my code
ArrayList<AdminUser> adminUsers = new ArrayList<>();
for (int i = 0; i < 10; i++) {
AdminUser adminUser = new AdminUser();
adminUser.setLoginName("qin").setPassword("asdfjj").setRoleId(1L).setDeptId(1L);
adminUsers.add(adminUser);
}
adminUserRepository.saveAll(adminUsers);
when I use jdbc, It works very well
String url = "jdbc:mysql://127.0.0.1:3306/study?rewriteBatchedStatements=true";
String user = "root";
String password = "asdfjj";
Connection connection = DriverManager.getConnection(url, user, password);
long start = System.currentTimeMillis();
System.out.println(start);
final String login_name = "qin";
final String login_password = "asdfjj";
PreparedStatement preparedStatement = connection
.prepareStatement("INSERT INTO admin_user (login_name, password, dept_id, role_id) VALUES (?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
preparedStatement.setString(1, login_name);
preparedStatement.setString(2, login_password);
preparedStatement.setInt(3, 1);
preparedStatement.setInt(4, 1);
preparedStatement.addBatch();
preparedStatement.setString(1, login_name);
preparedStatement.setString(2, login_password);
preparedStatement.setInt(3, 1);
preparedStatement.setInt(4, 1);
preparedStatement.addBatch();
preparedStatement.executeBatch();
ResultSet generatedKeys = preparedStatement.getGeneratedKeys();
while (generatedKeys.next()) {
long id = generatedKeys.getLong(1);
System.out.println(id);
}
jpa version: 3.3.2
hibernate version: 6.5.2