Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

Struts Problem Report
Struts has detected an unhandled exception:

Messages:
Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
File: org/springframework/orm/hibernate5/HibernateTemplate.java
Line number: 1,093
Stacktraces
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

解决方法1

涉及到数据库的读写都要添加 @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW )

    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW )
    @Override
    public void save(User user) {
        userDao.save(user);
    }

    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW )
    @Override
    public void update(User user) {
        userDao.update(user);
    }

    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW )
    @Override
    public void remove(User user) {
        userDao.remove(user);
    }

猜你喜欢

转载自www.cnblogs.com/liaoguanwang/p/9264322.html