flowable6.4使用oracle啓動不能自動創建表的坑

spring-boot整合flowable,oracle數據庫啓動報錯:

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLException: ORA-00942: 表或視圖不存在
### The error may exist in org/flowable/db/mapping/entity/Property.xml
### The error may involve org.flowable.engine.impl.persistence.entity.PropertyEntityImpl.selectProperty-Inline
### The error occurred while setting parameters
### SQL: select * from ACT_ID_USER where ID_ = ?
### Cause: java.sql.SQLException: ORA-00942: 表或視圖不存在
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
	at org.flowable.engine.common.impl.db.DbSqlSession.selectById(DbSqlSession.java:237)

,最後只生成幾個act_id_開頭的表:

很明顯,初始化flowable自帶表遇到錯誤意外終止。

檢查了下配置:

configuration.setDataSource(dataSource);
		configuration.setTransactionManager(transactionManager);
		configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
		configuration.setActivityFontName("宋體");
		configuration.setLabelFontName("宋體");
		configuration.setAnnotationFontName("宋體");
		configuration.setCustomSessionFactories(getCustomSessionFactories());
		configuration.setAsyncExecutorAsyncJobAcquisitionEnabled(false);
		configuration.setHistoryLevel(HistoryLevel.FULL);
		configuration.setIdGenerator(uuidGenerator());
		// 開啓內嵌的微型V5引擎,兼容V5的流程定義數據
		configuration.setFlowable5CompatibilityEnabled(true);
		configuration.setFlowable5CompatibilityHandlerFactory(springFlowable5CompatibilityHandlerFactory());

這個應該是我們沒有設置區分數據庫用戶Schema的問題,添加以下配置:

if (!CheckUtil.isNullorEmpty(defaultSchema))
		{
			configuration.setDatabaseSchema(defaultSchema);
		}

這個defaultSchema,是通過配置文件注入進來:

@Value("${spring.jpa.properties.hibernate.default_schema:}")
	private String defaultSchema;

其實這裏也就是setDatabaseSchema("FLOWABLE")而已,這個"FLOWABLE"是你的數據庫管理用戶名,注意要大寫哦。

這個時候,啓動,覺得應該是可以的了,畢竟mysql沒有區分用戶Schema的問題,初始化都一直是ok的,可惜的是結果是殘酷的,還是報了錯:

 

這個錯一看,應該就是oracle驅動的問題,後來經過排查,發現我們項目用的是ojdbc6,這個版本是沒有提供setSchema()方法的,那我就往上找最新的版本試試,於是找到了ojdbc7,發現這個版本是有提供setSchema(),所有就升級到ojdb7,重新啓動,成功了,表也自動創建了,問題得到了解決。

 

對了,如果啓動還是發現報錯,例如報錯爲:某某序列已存在,某某表已存在

那就要把已生成的act_開頭的表刪掉,再見序列是否有工作流引擎的序列,也刪掉:

 

爲此分享一下這個坑給大夥。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章