Connection is read-only. Queries leading to data modification are not allowed

Source: Internet
Author: User

Tag: exception Database

Connection is read-only. Queries leading to data modification are not allowed


<tx:advice id="txAdvice" transaction-manager="txManager"><tx:attributes>


<! -- Add all methods to transaction management. To improve efficiency, you can set some methods such as queries to read-only transactions. -->

<! -- Method name = *, readonly = true indicates that all database operations can be used, but only the database can be read.
For example, the listusers method of userservice can be used to retrieve all users.
However, if it is the userservice method deluser, you must delete the user at the DaO layer. The following error is reported:
Connection is read-only. Queries leading to data modification are not allowed.
Therefore, you must add the following add *, del *, update *, and so on. Grant the database access permissions respectively.
-->
<tx:method name="*" propagation="REQUIRED" read-only="true" />


<! -- The following methods are possible to design and modify methods, so they cannot be set as read-only -->
<tx:method name="add*" propagation="REQUIRED" /><tx:method name="del*" propagation="REQUIRED" /><tx:method name="update*" propagation="REQUIRED" /><tx:method name="save*" propagation="REQUIRED" /><tx:method name="create*" propagation="REQUIRED" /><tx:method name="clear*" propagation="REQUIRED" /></tx:attributes></tx:advice>

In the preceding bean. xml configuration, add *, del *, and update * are not configured at the beginning. An error occurs when the corresponding method is called.
However, it is okay to obtain data because
<tx:method name="*" propagation="REQUIRED" read-only="true" />
 
<PRE name = "code" class = "html"> <context: component-scan base-package = "com. eq3z"/> <! -- Configure the Transaction Manager --> <bean id = "transactionmanager" class = "org. springframework. orm. hibernate3.hibernatetransactionmanager "> <property name =" sessionfactory "ref =" sessionfactory "/> </bean> <! -- Configure the transaction propagation feature --> <TX: Advice id = "txadvice" transaction-Manager = "transactionmanager"> <TX: Attributes> <TX: method Name = "Save *" propagation = "required"/> <TX: method name = "Update *" propagation = "required"/> <TX: method Name = "delete *" propagation = "required"/> <TX: method name = "*" Read-Only = "true"/> </TX: attributes> </TX: Advice> <! -- Define how to use Transaction Management --> <AOP: config> <AOP: pointcut id = "managermethod" expression = "execution (* COM. service. *. *(..)) "/> <AOP: Advisor pointcut-ref =" managermethod "advice-ref =" txadvice "/> </AOP: config>


 


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.