3. call a class in action and inject the class into spring. In this class, the dao operation times: org. springframework. dao. invalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode. NEVER/MANUAL): Turn your Session into FlushMode. COMMIT/AUTO or remove 'readonly' marker from transaction definition. this error occurs. Cause: When S2SH is used in the project, OpenSessionInViewFilter is enabled to prevent loading delays. However, when OpenSessionInViewFilter is enabled, MANUAL is set by default in FlushMode, if FlushMode is MANUAL or NEVEL, Hibernate sets the transaction to readonly during the operation. therefore, when you add, delete, or modify an object, the preceding error is reported.
Solution: directly modify the configuration of OpenSessionInViewFilter and specify flushMode When configuring the filter. Use the following method: the code is as follows: add the following code to the web. xml file: This solves the problem of delayed loading and the preceding error message.
<! --
Hibernate does not really query data in the action because of delayed loading.
When you jump to the jsp page to display data, the session in hibernate is closed, so that the data cannot be displayed. This filter can be avoided.
-->
<Filter>
<Filter-name> OpenSessionInViewFilter </filter-name> <filter-class> org. springframework. orm. hibernate3.support. OpenS essionInViewFilter
</Filter-class>
<Init-param>
<Param-name> flushMode </param-name>
<Param-value> AUTO </param-value>
</Init-param>
</Filter>
<Filter-mapping>
<Filter-name> OpenSessionInViewFilter </filter-name>
<Url-pattern>/* </url-pattern>
</Filter-mapping>