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>