Insert data with the insert method in mybatis, the return value is 1, but the database has no data

Use in mybatis

<insert id="add" parameterType="cn.entity.Computer">
  insert INTO MyTable(createModel) VALUES(#{createModel})
</insert>

Wrote this in test class

int count = sqlSession.getMapper(ComputerMapper.class).add(com1);

The result is count=1

However, the inserted data was not found in the database. After looking for it, it turned out to be written

factory.openSession(false);

When setting no auto-commit

Add after the return count

sqlSession.commit();

That's it, commit the transaction.

If the factory.openSession(false) parameter above is changed to true, that is, factory.openSession(true);

Then when 1 is returned, the data is added to the database and automatically submitted


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325395721&siteId=291194637