Results 1 to 5 of 5

Thread: Transactionality doesnt work properly

  1. #1
    Join Date
    Dec 2011
    Posts
    3

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

    thanks!!

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    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.
    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
    Dec 2011
    Posts
    3

    Default

    I have this for @transaction works
    <!-- TRANSACTION MANAGEMENT -->
    <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
    cbosCreateInit.clean();
    // 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. #4
    Join Date
    Dec 2011
    Posts
    3

    Default

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

    Default

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

Posting Permissions

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