【问题标题】:Junit test failed in Ant, but succesfully finished in EclipseJunit 测试在 Ant 中失败,但在 Eclipse 中成功完成
【发布时间】:2012-02-08 01:10:07
【问题描述】:

我正在通过 Eclipse 运行我的 junit 测试,一切正常,包括下面的插入。 当我从命令行通过 ant 运行它时,我得到:

org.springframework.jdbc.BadSqlGrammarException: StatementCallback;错误的 SQL 语法 [插入实验 (id, name, description, journal, user_access) values('1', 'experimentOne', 'first Experiment', 'references 1', 'public')];嵌套异常是 java.sql.SQLException:列计数在语句中不匹配 [插入到实验元数据(id、名称、描述、journal_references、user_access)中。

有人可以帮忙吗?我确信 sql 语句是正确的。 提前致谢。

【问题讨论】:

  • 查询生成有问题。查询执行是“插入实验”,但在例外情况下,您会得到“插入实验元数据”。您能否检查您是否没有使用拦截器或修改的 jdbc 驱动程序进行任何动态查询更新。 '_metadata' 字符串显然是由您的代码更新的,而不是 spring 的。另外,您使用什么数据库?
  • 很抱歉我在发送之前修改了查询,它实际上是插入到experiment_metadata中。它抱怨列数错误...看起来它加载了错误的模式,即使:hibernate.hbm2ddl.auto=create-drop,正如 II 提到的,它在 Eclipse 中工作得很好。
  • 你能将示例项目发布到 github 的某个地方吗?另外,您使用什么数据库,您可以设置调试点并验证架构是否实际被删除。
  • 您能否解释一下我如何在我的 junit 测试用例中调试导出了哪个架构并且它实际上被删除了?
  • 我们使用的是 Spring,Hibernate

标签: eclipse hibernate spring ant junit


【解决方案1】:

回答:我想通了。我们有一个带有旧类的 jar,它反映了类路径中的旧模式。 该 jar 包含在 ant 中,而不包含在 Eclipse 中。

关于如何导出架构:
LocalSessionFactoryBean localfactory1 = (LocalSessionFactoryBean)this.getApplicationContext().getBean("&readOnlySessionFactory");

    String customImportFile = "customImportFile.txt";
    System.err.println("Performing schema export with custom import file: '"
            + customImportFile + "'.");
    System.err.println("------JdbcTemplate" + jdbcTemplate.getDataSource());


    try {
    SchemaExport export = new SchemaExport(localfactory1.getConfiguration(), localfactory1.getDataSource().getConnection());
    export.setOutputFile(customImportFile);
    export.create(false, true);
    }
    catch (Exception exp)
    {
        exp.printStackTrace();
    }  

【讨论】:

    猜你喜欢
    • 2012-11-04
    • 2014-03-08
    • 1970-01-01
    • 2013-08-16
    • 2010-10-12
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    相关资源
    最近更新 更多