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 :-)
You didn't commit your transaction. Try adding a "session.commit()".