現象描述:按照正常配置,第一次啟動時不能自動建表
關鍵配置片段如下:
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="true" />
</bean>
啟動后報錯:
### The error may exist in org/activiti/db/mapping/entity/Property.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select VALUE_ from ACT_GE_PROPERTY where NAME_ = 'schema.version'
### Cause: java.sql.SQLSyntaxErrorException: ORA-00942: 表或視圖不存在
經過調試分析,發現是關鍵判斷表是否存在代碼返回true值引起的,org.activiti.engine.impl.db.DbSqlSession.isTablePresent(String tableName);問題在於方法里面的schema=null,而連接的數據庫實例下已經有另外一個用戶activiti已經創建過表。
於是在引擎配置里面加入屬性:
<property name="databaseSchema" value="act"/>
再啟動,成功創建表。到此本以為問題已解決,停掉服務再次啟動,失敗,報建表錯誤:對象已存在。調試發現isTablePresent返回的還是false(表還未創建)。
發現是大小寫問題,最后改成
<property name="databaseSchema" value="ACT"/>
解決。