2014-08-28 59 views
0

我是想在我們的項目中使用DbUnit和正在運行到一個問題。想知道你是否能夠提供幫助。HSQLDB:org.dbunit.dataset.DataSetException:java.sql.SQLSyntaxErrorException:用戶缺少特權或找不到對象:TRIGGER_CATALOG

使用@ExpectedDatabase(「file.xml」)的註釋,並且在處理該林,林在這個執行點:

at org.dbunit.database.DatabaseDataSet.getTableMetaData(DatabaseDataSet.java:295) 
at org.dbunit.database.DatabaseDataSet.getTable(DatabaseDataSet.java:314) 
at com.github.springtestdbunit.assertion.NonStrictDatabaseAssertion.assertEquals(NonStrictDatabaseAssertion.java:43) 
at com.github.springtestdbunit.DbUnitRunner.verifyExpected(DbUnitRunner.java:130) 
at com.github.springtestdbunit.DbUnitRunner.afterTestMethod(DbUnitRunner.java:70) 
at com.github.springtestdbunit.DbUnitTestExecutionListener.afterTestMethod(DbUnitTestExecutionListener.java:165) 
at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:416) 
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:91) 
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) 
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233) 
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176) 
at org.junit.runner.JUnitCore.run(JUnitCore.java:160) 
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77) 
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195) 
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63) 

我在file.xml多個表,其中兩個是組織和觸發。 正在處理組織表時,在此行返回的元數據對象恰好有3列:organization_id,名稱和狀態。這些是我的組織表所具有的3列。

但在處理觸發器,在相同的執行點,元數據爲空,所以它執行進一步線299,並呼籲:

// Create metadata and cache it 
metaData = new DatabaseTableMetaData(tableName, _connection, true, super.isCaseSensitiveTableNames()); 

返回這個元數據有很多,我不列有我的表(TRIGGER_CATALOG,EVENT_MANIPULATION,ACTION_TIMING等)

預計列(我在架構有這些):

TRIGGER_ID 
TRIGGER_EXTERNAL_ID 
TRIGGER_NAME (First occurrence. See below) 
STATUS 
CREATED_BY 
CREATED_ON 
UPDATED_BY 
UPDATED_ON 

未知科拉姆NS(我沒有這在我的架構):

TRIGGER_CATALOG 
TRIGGER_SCHEMA 
TRIGGER_NAME (Yes, This appears twice on the meta data. On the top probably from my schema, and here from reserved info/magic??) 
EVENT_MANIPULATION 
EVENT_OBJECT_CATALOG 
EVENT_OBJECT_SCHEMA 
EVENT_OBJECT_TABLE 
ACTION_ORDER 
ACTION_CONDITION 
ACTION_STATEMENT 
ACTION_ORIENTATION 
ACTION_TIMING 
ACTION_REFERENCE_OLD_TABLE 
ACTION_REFERENCE_NEW_TABLE 
ACTION_REFERENCE_OLD_ROW 
ACTION_REFERENCE_NEW_ROW 
CREATED 

由於這一點,它拋出一個異常:

org.dbunit.dataset.DataSetException: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: TRIGGER_CATALOG 
    at org.dbunit.database.DatabaseDataSet.getTable(DatabaseDataSet.java:323) 
    at com.github.springtestdbunit.assertion.NonStrictDatabaseAssertion.assertEquals(NonStrictDatabaseAssertion.java:43) 
    at com.github.springtestdbunit.DbUnitRunner.verifyExpected(DbUnitRunner.java:130) 
    at com.github.springtestdbunit.DbUnitRunner.afterTestMethod(DbUnitRunner.java:70) 
    at com.github.springtestdbunit.DbUnitTestExecutionListener.afterTestMethod(DbUnitTestExecutionListener.java:165) 

這是發生因爲即時通訊用的是「觸發器」我的表名?觸發器是DBUnit還是HSQLDB中的保留關鍵字?如果我查看DatabaseDataSet._tableMap hashmap中的其他表,所有其他表似乎都很健康,並且在我們對應的元數據對象中包含了我期望的列。 即時通訊使用Maven的項目有:

<dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.11</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-test</artifactId> 
     <version>${org.springframework.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hsqldb</groupId> 
     <artifactId>hsqldb</artifactId> 
     <version>2.3.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.dbunit</groupId> 
     <artifactId>dbunit</artifactId> 
     <version>2.5.0</version> 
    </dependency> 
    <dependency> 
     <groupId>com.github.springtestdbunit</groupId> 
     <artifactId>spring-test-dbunit</artifactId> 
     <version>1.1.0</version> 
    </dependency> 

任何幫助將不勝感激。

我的測試類是什麼樣子:

public class TriggerServiceTest extends DBBaseTest { 
    @Autowired 
    private TriggerService triggerService; 
    @Test 
    @DatabaseSetup(value={"classpath:testData/trigger/Trigger_Test_2_Init.xml"}, type = DatabaseOperation.CLEAN_INSERT) 
    @ExpectedDatabase(value="classpath:testData/trigger/Trigger_Test_2.xml", assertionMode = DatabaseAssertionMode.NON_STRICT) 
    @DatabaseTearDown(value={"classpath:testData/trigger/Trigger_Test_2_Init.xml"}, type = DatabaseOperation.DELETE) 
    public void testTriggerWrite(){ 
     TriggerDTO triggerDTO = new TriggerDTO(); 
     triggerDTO.setName("Trigger_Test_1"); 
     triggerDTO.setId("101"); 
     String newId = triggerService.write(triggerDTO); 
     System.out.println("Done."); 
    } 
} 

而且DBBaseTest:

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations = {"classpath:wfxSpringDatabaseTest.xml" , "classpath:wfxTriggerContextTest.xml"}) 
public abstract class DBBaseTest extends AbstractJUnit4SpringContextTests { 
    @Before 
    public void setApplicationContext() { 
     ApplicationContextHolder.setTheGlobalAppContext(applicationContext); 
    } 
} 

TESTDATA /觸發/ Trigger_Test_2.xml:

<?xml version='1.0' encoding='UTF-8'?> 
<dataset> 
    <organization organization_id="1" name="MyOrg" status="Active"/> 
    <users user_id="1" username="admin" password="pwd123" email="[email protected]" full_name="The Admin" status="Active" created_on="2013-08-17 03:45:44.0" created_by="1" is_admin="1" secret_question="What is your favorite sport?" secret_answer="Quiddich" enabled="1" organization_id="1"/> 
    <triggers trigger_id="101" trigger_EXTERNAL_id="101" trigger_name="Trigger_101" status="Active" created_by="1" created_on="2014-08-26 11:34:25.625" updated_by="1" updated_on="2014-08-26 11:34:25.625"/> 
</dataset> 

TESTDATA /觸發/ Trigger_Test_2_Init.xml:

<?xml version='1.0' encoding='UTF-8'?> 
<dataset> 
    <organization organization_id="1" name="MyOrg" status="Active"/> 
    <users user_id="1" username="admin" password="pwd123" email="[email protected]" full_name="The Admin" status="Active" created_on="2013-08-17 03:45:44.0" created_by="1" is_admin="1" secret_question="What is your favorite sport?" secret_answer="Quiddich" enabled="1" organization_id="1"/> 
    <triggers/> 
</dataset> 
+0

<刪除評論> – Deven 2014-08-28 02:43:43

回答

0

確認這是發生由於「觸發器」字。這可能是HSQLDB中的保留關鍵字。將其更改爲「triggers_table」後,一切正常。請參考以下鏈接,所有保留的關鍵字在HSQLDB:

http://hsqldb.org/doc/guide/lists-app.html

相關問題