0

I am running my junit tests through Eclipse, everything works just fine,including inserts bellow. When I am running it through ant from comand line I am getting :

org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [insert into experiment (id, name, description, journal, user_access) values('1', 'experimentOne', 'first experiment', 'references 1', 'public')]; nested exception is java.sql.SQLException: Column count does not match in statement [insert into experiment_metadata (id, name, description, journal_references, user_access).

Can sombody help? I am sure that sql statement is correct. Thanks in advance.

Ralph
  • 118,862
  • 56
  • 287
  • 383
  • 1
    Something wrong with query generation. Query execute is 'insert into experiment', but in exception you're getting 'insert into experiment_metadata'. Can you check if you are not doing any dynamic query updates w/ interceptors or modified jdbc driver. '_metadata' string clearly was updated by your code, not spring's one. Also, what database do you use? – Petro Semeniuk Feb 08 '12 at 01:41
  • I am sorry I modified the query before sending it, it is actually insert into experiment_metadata. It is complaining about wrong number of column...It looks like it loading a wrong schema, even though: hibernate.hbm2ddl.auto=create-drop, and as II mentioned it works in Eclipse just fine. – Masha Ivanova Feb 08 '12 at 20:25
  • Can you post sample project somewhere into github. Also, what database do you use, can you set debug point and verify that schema was actually dropped. – Petro Semeniuk Feb 08 '12 at 22:29
  • Can you , please, explain how I can debug in my junit test case which schema was exported and was it actually dropped? – Masha Ivanova Feb 09 '12 at 03:00
  • We are using Spring, Hibernate – Masha Ivanova Feb 09 '12 at 03:19
  • For showing sql statements look into http://stackoverflow.com/questions/2536829/hibernate-show-real-sql. If that won't help you can monitor which sql queries goes into database - oracle/sql server usually have good toolset for this. What database vendor do you use? – Petro Semeniuk Feb 09 '12 at 03:29

1 Answers1

2

Answer: I figured it out. We had a jar with old classes, that reflected an old schema in our classpath. That jar was included in ant, and not included in Eclipse.

Regarding how to export a schema:
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();
    }