flowable6.4使用oracle启动不能自动创建表的坑

本文解决Spring Boot整合Flowable在Oracle环境下初始化表结构失败的问题,涉及ojdbc6升级至ojdbc7以支持setSchema()方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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_开头的表删掉,再见序列是否有工作流引擎的序列,也删掉:

 

为此分享一下这个坑给大伙。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值