Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MyBatis 3.0.1 insert problem

Decided to move one of my project from iBatis to MyBatis and ran into a problem with insert.

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.

the table in use:

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

I'm trying to run this with mybatis 3.0.1, spring 3.0.3, postgresql 8.3 ( using postgresql-8.4-701.jdbc3.jar )

I believe all boilerplate setup is set up properly (I can execute a select against another table fine.

I tested the inser manually and it works just fine ( insert into test_a ( cookie ) values( 'some stuff'); )

For some reason the insert does not execute and no stack trace shows up :-(

Any hints will be most appreciated :-)

like image 658
vector Avatar asked Jun 23 '10 21:06

vector


1 Answers

You didn't commit your transaction. Try adding a "session.commit()".

like image 126
user359996 Avatar answered Sep 23 '22 12:09

user359996