如何更改dbunit getConnection尽管它是最终的

时间:2015-08-07 20:46:22

标签: java oracle dbunit

我正在运行dbunit 2.4.9。切换到新的oracle实例后,我收到AmbiguousTableNameException。 doc表示我应该在创建时将模式名称放在连接中。但我不能覆盖DBTestCase上的getConnection,因为它是最终的。我应该选择不同的超类吗?我忽略了什么吗?

这是我的测试用例类。

public abstract class DbTestCase extends DBTestCase
{
private static boolean doOnce = false;
private Session session;

public DbTestCase() throws Exception
{
    super();
    System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, "oracle.jdbc.driver.OracleDriver" );
    System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL, "jdbc:oracle:thin:@host:1521:sid" );
    System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_USERNAME, "id" );
    System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD, "xxxx_15" );
}


@Override
protected void setUp() throws Exception
{
    super.setUp();

    if(!doOnce){
        doOnce = true;          
        BasicConfigurator.configure();          
        MyHibernateFactory.initilize();
    }

    session = MyHibernateFactory.getSession();
    session.beginTransaction();
}

public void tearDown() throws Exception
{  
 ...
}  

@Override
protected IDataSet getDataSet() throws Exception
{
    return new FlatXmlDataSetBuilder().build(new FileInputStream("src/dbtest/dataset.xml"));
}

}

1 个答案:

答案 0 :(得分:0)

您可以使用PropertiesBasedJdbcDatabaseTester.DBUNIT_SCHEMA属性

    System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_SCHEMA, "SCHEMA" );