java – MyBatis 3.0. 1 insert questions

I decided to move one of my projects from ibatis to mybatis and encountered an insertion problem

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 file:

public interface ArticleMapper {
 void insertTestA();
}

Mapper implementation:

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.

Tables in use:

CREATE TABLE test_a
(
  cookie text
)
WITH (OIDS=FALSE);

I'm trying to use mybatis 3.0 1,spring 3.0. 3. Run PostgreSQL 8.3 (using postgresql-8.4-701.jdbc 3. Jar)

I believe that all template settings are set correctly (I can perform a selection on another table)

I manually tested inser and it worked well (insert the test_a (cookie) value ('some stuff ');)

For some reason, the insertion is not executed, and there is no stack trace display:-(

Any tips will be appreciated: -)

Solution

You have not submitted your transaction Try adding "session. Commit()"

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>