Jun中的Junit测试失败,但在Eclipse中成功完成

时间:2012-02-08 01:10:07

标签: eclipse hibernate spring ant junit

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

org.springframework.jdbc.BadSqlGrammarException: StatementCallback;错误的SQL语法[插入实验(id,name,description,journal,user_access)值('1','experimentOne','first experiment','references 1','public')];嵌套异常是java.sql.SQLException:列计数与语句[insert into experiment_metadata(id,name,description,journal_references,user_access)不匹配。

可以帮助吗?我确信sql语句是正确的。 提前谢谢。

1 个答案:

答案 0 :(得分:2)

答案:我明白了。我们有一个带有旧类的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();
    }