Announcement Announcement Module
No announcement yet.
Transactionality doesnt work properly Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transactionality doesnt work properly

    Hi all.

    I have a @Service called from two different sites.
    From the class1 there is a context which apply transactionality through <aop pointcut>
    From the class2. Its extends a class which is @Transaction annoted.

    Apparetly both places apply transaction correctly but is not. My test are split up in two types:

    - Insert data in a object and save the object (which is an entity). After this fill other object and save this object (an entity too). Until the process finish, the first object is not commit never. And if the process is stop before finish any commit are carried out. So thats work fine because I want to have every commit in the same transaction. All success or all fail.

    - In the second test there are 2 methods in the @Service. These methods make as the previous, fill in an object and save it. The problem is: enter in the method 1, and commit. Enter in the method 2 and stop the application. There is no rollback for the method 1, so the data are commited.

    The problem of the second test happend when the @service is called from the class which inherit @Transactional. When the @Service is called from the class with aop pointcut it works fine in both test.

    I dont find any conflict between @Transaction and pointcut in the documentation. And I dont understand why transactionality works in the @Service but not in the methods called from.

    I hope being clear in the explication.


  • #2
    I hope being clear in the explication.
    No it isn't... Post some code.

    Transactions don't work over methods so if I call from a non-transactional method 2 transactional methods those execute in 2 transactions. Also beware of the fact that spring uses proxies to apply AOP so as soon as you are inside a proxy interceptors don't apply anomore.

    @Transactional by itself does nothing... If you don't have a tx:annotation-driven the annotation is basically useless. Annotations are only metadata nothing more nothing less.


    • #3
      I have this for @transaction works
      <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager"/>
      <tx:annotation-driven transaction-manager="transactionManager" order="100"/>

      this test doesnt do rollback when stop application.

      Map<Long, Map<String, Collection<GrantedAuthority>>> currentPermissions = securityInformationManager.createSecurityMap(Arcad iaApplicationName.CBOS);

      // Clean the existing functionalities
      // Creates all the functionalities
      FunctionalityParser fp = new FunctionalityParser();
      int x=3/0;

      Within clean() method some tables are erased. The application fail later in x=3/0. And doesnt do rollback. What I want to is rollback of the transacction for the method clean.


      • #4
        I think the answer is in the spring documentation:
        Note: In proxy mode (which is the default), only 'external' method calls coming in through the proxy will be intercepted. This means that 'self-invocation', i.e. a method within the target object calling some other method of the target object, won't lead to an actual transaction at runtime even if the invoked method is marked with @Transactional!


        • #5
          And why should it rollback?! If that method isn't transactional you have individual transactions, so the clean is a separate transaction which is already committed... The method as a whole has to be transactional to have that rollback work.