Results 1 to 4 of 4

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

  1. #1
    Join Date
    Sep 2008
    Posts
    4

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2008
    Posts
    4

    Default

    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?

  4. #4
    Join Date
    Mar 2007
    Location
    Poland
    Posts
    341

    Default

    Quote 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 
    ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •