views:

98

answers:

1

Hi Everyone! 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"&gt;
<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 :-)

+2  A: 

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

YOU SAVED THE DAY! THANK YOU SO MUCH!... talk about feeling embarrassed now. I thought I looked at the skimpy examples in the new, skimpy manual pretty closely. Turns out it session.commit() is mentioned once on page 56 of 64 :-(How about that. Anyway, thanks again!
vector