Org. springframework. dao. InvalidDataAccessApiUsageException

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.