transaction management using Spring


Web tier: servlets, JSP, Web frameworks: transaction management using Spring

  1. transaction management using Spring (3 messages)


    I have a requirement where I need to call a method with transaction propagation level based on the incoming request. Lets request 1 comes for method A with Required_new propogation level where as request2 comes for method A with Required propogation level (propagation level will be decided run time). So there different propgation levels on a single method which will be decided runtime. We are using spring's declarative transaction management with annotation (@transaction (....)). What are the ways to do this.

    One of the solutions I am thinking about is to wrap the @Transaction annotation in a custom annotation and call the @transaction with different attributes based on the incoming request. Not sure if this will work as haven't tried yet. 

    Please let me know if anybody has solution to this.




  2. Make sure to have either REQUIRED or SUPPORTS propagation levels in your method. They will use the Propagation level coming from the client, if any.

  3. Can you elaborate on this ? I will have propagation level as REQUIRED but if the client request needs it to be NESTED or REQUIRED_NEW then methods propagation level needs to be reset. There could be multiple client requests with diffrent requirements of propagation level so the methods level (annotation) can't be kept static.


    Alternative I am thinking of now is to use the proxy which will set the propagation level as trasanction attributes before actual method calls but then it needs have same method copied for each level. e.g. methodA with REQUIRED, methodA with REQUIRED_NEW and so on.

    Please let me know if anybody knows a better alternative.



  4. One more thing to add, there is no existing transaction till to the point of calling this method. This methods creates transaction for the client and needs information from client on what level want.Execution of the method happens within transaction with defined attibutes.