决定将我的一个项目从iBatis移到MyBatis并遇到插入问题.
mapper xml:
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="bap.persistance.interfaces.ArticleMapper">
- <insert id="insertTestA">
- insert into test_a ( cookie ) values( 'tomek pilot');
- </insert>
- </mapper>
mapper java文件:
- public interface ArticleMapper {
- void insertTestA();
- }
映射器实现:
- String resource = "bap/persistance/MyBatis_xml/MyBatisConfig.xml";
- ....
- ...
- public void createArticle( Article article ) throws IOException {
- Reader reader = Resources.getResourceAsReader(resource);
- sqlSessionFactory sqlSessionFactory =
- new sqlSessionFactoryBuilder().build(reader);
- sqlSession session = sqlSessionFactory.openSession();
- try{
- ArticleMapper mapper = session.getMapper(ArticleMapper.class);
- mapper.insertTestA();
- } catch( Exception e ){
- e.printStackTrace();
- } finally{
- session.close();
- }
- return article.getId();
- }
- ...
- ... line omitted for brevity.
使用中的表格:
- CREATE TABLE test_a
- (
- cookie text
- )
- WITH (OIDS=FALSE);
我正在尝试使用mybatis 3.0.1,spring 3.0.3,postgresql 8.3(使用postgresql-8.4-701.jdbc3.jar)运行它
我相信所有样板设置都已正确设置(我可以对另一个表执行精选.
我手动测试了inser并且它工作得很好(插入test_a(cookie)值(‘some stuff’);)
由于某种原因插入不执行,没有堆栈跟踪显示:-(
任何提示将非常感激:-)
解决方法
您没有提交您的交易.尝试添加“session.commit()”.