MyBatis 3.0.1插入问题

发布于 2024-09-06 15:44:10 字数 1592 浏览 8 评论 0 原文

决定将我的一个项目从 iBatis 迁移到 MyBatis,并遇到了插入问题。

映射器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>

映射器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)运行它

我相信所有样板设置已正确设置(我可以很好地对另一个表执行选择。

我手动测试了插入器,它工作得很好( insert into test_a ( cookie ) values( 'some stuff');

由于某种原因,插入不执行并且没有显示堆栈跟踪:-(

任何提示将不胜感激:-)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲凉≈ 2024-09-13 15:44:10

您没有提交交易。尝试添加“session.commit()”。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文