0
<dataset>
 <user id="1" created_date='2017-01-01 00:00:00' email="" user_name="root"/>
</dataset>

xml above gives me error. The problem is i have reserved word for user. how can I solve this. any links?

updated

I am using spring boot, spring data jpa, spring-test-dbunit, dbunit, postgresql

roki
  • 348
  • 3
  • 15
  • 1
    `user` is a reserved keyword, it has to be quoted: `"user"`. You will have a lot less trouble if you find a different name that is not a reserved keyword –  Feb 24 '17 at 06:52
  • @a_horse_with_no_name could you please show how to quote reserved word. I tried but could not <`user` id="1" created_date='2017-01-01 00:00:00' email="" user_name="root"/> none of these work "" '' – roki Feb 24 '17 at 08:02
  • 1
    In SQL you simply use `"user"` I don't know how you would do that in DbUnit's XML. But again: try to find a name that doesn't require quoting. You will save yourself a lot of trouble (DbUnit's apparent inability to properly deal with reserved keywords is just one one example) –  Feb 24 '17 at 08:09

1 Answers1

0

According to this forum https://sourceforge.net/p/dbunit/mailman/message/20643023/ it doesn’t seem like DBUnit has a way to “quote” the table name. But you can configure DatabaseDataSourceConnectionFactoryBean if you do not want to rename tables for some reason or working with legacy database

@Configuration
public class Custom.... {

    @Autowired
    private DataSource dataSource;

    @Bean
    public DatabaseConfigBean dbUnitDatabaseConfig() {
        DatabaseConfigBean dbConfigBean = new DatabaseConfigBean();
//        dbConfigBean.setDatatypeFactory(new PostgresqlDataTypeFactory());
        dbConfigBean.setQualifiedTableNames(true);
        return dbConfigBean;
    }

    @Bean
    public DatabaseDataSourceConnectionFactoryBean dbUnitDatabaseConnection() {
        DatabaseDataSourceConnectionFactoryBean databaseDataSourceConnectionFactoryBean = new DatabaseDataSourceConnectionFactoryBean(dataSource);
        databaseDataSourceConnectionFactoryBean.setDatabaseConfig(dbUnitDatabaseConfig());
        return databaseDataSourceConnectionFactoryBean;
    }
}

After setting true to qualifiedTableNames you should give full name for ur tables in xml

<public.user id="1" created_date='2017-01-01 00:00:00' email="root@demo.io" password="your password"  username="root"/>
roki
  • 348
  • 3
  • 15