2012-02-08 157 views
0

我正在運行我的junit測試,通過Eclipse,一切正常,包括插入波紋管。 當我運行它通過螞蟻從COMAND行我得到:Junit測試在Ant中失敗,但在Eclipse中成功完成

org.springframework.jdbc.BadSqlGrammarException: StatementCallback;錯誤的SQL語法[insert into experiment(id,name,description,journal,user_access)values('1','experimentOne','first experiment','references 1','public')];嵌套異常是java.sql.SQLException:列計數在語句中不匹配[insert into experiment_metadata(id,name,description,journal_references,user_access)。

可以幫助嗎?我確信sql語句是正確的。 在此先感謝。

+1

查詢生成有問題。查詢執行是'insert into experiment',但是在例外情況下,您將'insert into experiment_metadata'。你可以檢查你是否沒有做任何動態查詢更新w /攔截器或修改的jdbc驅動程序。 '_metadata'字符串顯然已被您的代碼更新,而不是春天的。另外,你使用什麼數據庫? – 2012-02-08 01:41:21

+0

對不起,我發送它之前修改了查詢,它實際上是插入到experiment_metadata中。它抱怨錯誤的列數......它看起來像加載了一個錯誤的模式,即使:hibernate.hbm2ddl.auto = create-drop,正如我提到它在Eclipse中工作得很好。 – 2012-02-08 20:25:28

+0

你可以將示例項目發佈到github的某處嗎?另外,您使用的數據庫是否可以設置調試點並驗證模式實際上是否已被刪除。 – 2012-02-08 22:29:14

回答

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(); 
    } 
+0

好的。將答案標記爲已接受:-) – 2012-02-15 02:27:08

相關問題