Announcement Announcement Module
Collapse
No announcement yet.
read-only attribute in tx:advice seem not to work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • read-only attribute in tx:advice seem not to work

    Hi there,
    I am new to Spring. I am trying to implement transaction management by spring APO framework.
    I set my txAdvice's attribute for my get* method is read-only, but I dont know why if I force the implementation as the update statement in that method,it still succeeds completing the transaction.
    Can someone please tell me why?

  • #2
    read-only doesn't enforce anything. It is merely a hint to the underlying JDBC driver if it feels free to ignore it it ignores it. So it depends highly on your underlying JDBC driver implementation if the read-only flag is going to work.

    Comment


    • #3
      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?

      Comment


      • #4
        Originally posted by hello_world View Post
        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 
        ...

        Comment

        Working...
        X