记一次数据插入错误:
在创建service层的时候加入了事务的注解,并设置为了只读模式,在service层中加入了新增的方法,启动的时候报下面的错误
Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowedat org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)at org.activiti.engine.impl.db.DbSqlSession.flushRegularInsert(DbSqlSession.java:649)at org.activiti.engine.impl.db.DbSqlSession.flushInsertEntities(DbSqlSession.java:544)at org.activiti.engine.impl.db.DbSqlSession.flushInserts(DbSqlSession.java:527)at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:417)at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:197)
错误原因
在业务层加入了下面的注解
@Service@Transactional(readOnly = true)
解决方法
在新增加的方法上将只读改成 false 即可
@Override@Transactional(readOnly = false)