当前位置: 代码迷 >> 综合 >> Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition
  详细解决方案

Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition

热度:71   发布时间:2023-12-17 00:57:30.0

使用hibernate的封装的create方法报错如下:

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.at org.springframework.orm.hibernate4.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1135)at org.springframework.orm.hibernate4.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:620)at org.springframework.orm.hibernate4.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:617)at org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:340)at org.springframework.orm.hibernate4.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:308)at org.springframework.orm.hibernate4.HibernateTemplate.save(HibernateTemplate.java:617)at cn.gov.zjport.skeleton3.dao.base.impl.BaseDaoImpl.create(BaseDaoImpl.java:134)at cn.gov.zjport.pen.common.service.mq.PenDesResultManager.execute(PenDesResultManager.java:114)at cn.gov.zjport.pen.restapi.config.TaskSchedule.execute1(TaskSchedule.java:29)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)at java.util.concurrent.FutureTask.run(FutureTask.java:266)at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)at java.lang.Thread.run(Thread.java:745)

什么当前会话只能只读,需要去掉只读,
在当前方法上加上注解:

 @Transactional(readOnly = false)

解决了,没有细纠,用的不多了…解决就好了…

  相关解决方案