abel533/Mybatis-Spring

通用Mapper 0.2.0: java.lang.AssertionError: Expected exception: org.apache.ibatis.exceptions.PersistenceException

pi408637535 opened this issue · 1 comments

你好,由于对于通用Mapper我可能看不太懂,所以我决定先来看这个低版本。
我的数据库是Mysql。
配置文件:







public class Country {
@id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String countryname;
private String countrycode;
}

Reader reader = Resources.getResourceAsReader("mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
//创建数据库
SqlSession session = null;
try {
session = sqlSessionFactory.openSession();
} finally {
if (session != null) {
session.close();
}
}
...
}

country 结构
CREATE TABLE country (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
countryname varchar(32) DEFAULT NULL,
countrycode varchar(2) DEFAULT 'HH',
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=188

Mybatis日志:
DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@47faa49c]
DEBUG [main] - ==> Preparing: INSERT INTO COUNTRY (ID,COUNTRYNAME,COUNTRYCODE) VALUES ( ?,?,? )
DEBUG [main] - ==> Parameters: null, yyy(String), t(String)
DEBUG [main] - <== Updates: 1
DEBUG [main] - ==> Executing: SELECT LAST_INSERT_ID()
TRACE [main] - <== Columns: LAST_INSERT_ID()
TRACE [main] - <== Row: 190
DEBUG [main] - <== Total: 1
DEBUG [main] - Rolling back JDBC Connection [com.mysql.jdbc.JDBC4Connection@47faa49c]
DEBUG [main] - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@47faa49c]
DEBUG [main] - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@47faa49c]
DEBUG [main] - Returned connection 1207608476 to pool.
Disconnected from the target VM, address: '127.0.0.1:55572', transport: 'socket'

java.lang.AssertionError: Expected exception: org.apache.ibatis.exceptions.PersistenceException

我是真没明白这个错误是怎么发生了,希望能得到答复

看不出来原因