
Originally Posted by
hello_world
Thanks alot for your answer. Can you please tell me how to check if the method in the Spring IoC tx:method is advised as "read-only",but in my implementation this method is accidentally implemented with insert or update,will the program throw an exception or warning?
Asfaik the answer for the question is a little bit complicated. readonly is like a marker/hint to tell jdbc that we are not executing any DML operations.
This hint can be ignored by jdbc drive (for example ORACLE does not have any notion of read only sessions) but maybe on some of db this can give you a performance gain. Make test to see if you have any log statements about modifying (insert,update) in Spring logs.
It is all when talking about JDBC.
If you have readonly marker on methods that use hibernate your session will be in FlsuhMode.Never/Manual mode. Any write operations will throw exception:
Code:
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.
at org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1182)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:692)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:690)
at
...