We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.5.5
MS Sql Server 2008 R2,MS Sql Server 2019 com.microsoft.sqlserver:mssql-jdbc:8.4.0.jre8 com.microsoft.sqlserver:mssql-jdbc:7.4.1.jre8
Table:
CREATE TABLE [dbo].[student]( [id] [int] IDENTITY(1,1) NOT NULL, [name] [varchar](50) NOT NULL, CONSTRAINT [PK_student] PRIMARY KEY CLUSTERED ( [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO
Entity:
public class Student implements Serializable { private static final long serialVersionUID = -9113130818289196330L; private Integer id; private String name; }
dao:
public interface StudentMapper { int batchInsert(List<Student> list); }
mapper:
<insert id="batchInsert" keyProperty="id" parameterType="java.util.List" useGeneratedKeys="true"> insert into student (name) values <foreach collection="list" item="item" separator="," index="index"> (#{item.name,jdbcType=VARCHAR}) </foreach> </insert>
test:
@Test void batchInsert() { Student student1=new Student(); student1.setName("Jack"); Student student2=new Student(); student2.setName("Tom"); List<Student>students=new ArrayList<>(); students.add(student1); students.add(student2); studentMapper.batchInsert(students); students.forEach( e->{ log.info("{}",e.getId()); } ); }
10 9
2020-08-03 22:42:35.691 INFO 1940 --- [ Test worker] c.e.testbatch.dao.StudentMapperTest : 10 2020-08-03 22:42:35.692 INFO 1940 --- [ Test worker] c.e.testbatch.dao.StudentMapperTest : null
The text was updated successfully, but these errors were encountered:
Hello @xiongbb ,
This is the same report as #1439 and the driver still does not support it, unfortunately. microsoft/mssql-jdbc#245
Closing as there is nothing MyBatis can do.
Sorry, something went wrong.
@harawata Thanks for your reply, I got it
<select id="batchInsert" parameterType="java.util.List" resultType="java.lang.Integer"> insert into student (name) output inserted.id values <foreach collection="list" item="item" separator="," index="index"> (#{item.name,jdbcType=VARCHAR}) </foreach> </select>
No branches or pull requests
MyBatis version
3.5.5
Database vendor and version
MS Sql Server 2008 R2,MS Sql Server 2019
com.microsoft.sqlserver:mssql-jdbc:8.4.0.jre8
com.microsoft.sqlserver:mssql-jdbc:7.4.1.jre8
Test case or example project
Table:
Entity:
dao:
mapper:
test:
Steps to reproduce
Expected result
10
9
Actual result
2020-08-03 22:42:35.691 INFO 1940 --- [ Test worker] c.e.testbatch.dao.StudentMapperTest : 10
2020-08-03 22:42:35.692 INFO 1940 --- [ Test worker] c.e.testbatch.dao.StudentMapperTest : null
The text was updated successfully, but these errors were encountered: