Results 1 to 5 of 5

Thread: Transaction propagation

  1. #1
    Join Date
    Aug 2005
    Posts
    2

    Default Transaction propagation

    Hi,
    I have a jar file for data access. it manages the transactions using Spring. i use GenericApplicationContext to load beans and transaction information.

    This jar file is used in many web applications, that doesn't initiate any transactions, to access and update data.

    Now if i build a new web application using struts MVC or spring MVC that initiates its own transactions, is it possible for the jar file data access objects to participate in that tranaction instead of their own tranaction.

    I am new to Spring! i really appreciate your help.

    Thanks,
    -Mettu.

  2. #2
    Join Date
    Aug 2005
    Location
    Romania
    Posts
    10

    Default

    One solution that I see right now is to use POJO wrappers over your "jar" objects, and make these POJO's to participate in a transaction e.g thourgh TransactionProxyFactoryBean.

  3. #3
    Join Date
    Aug 2005
    Posts
    2

    Default Transaction Propagation

    Hi Marius,
    Thanks for the reply! these are the layers i have in jar file
    Service layer - which is accessed by web applications
    - relies on Broker layer for actual database operations
    Broker Layer - does actual database access and update work.
    i defined the transactions at Broker level in the jar file.

    Now can the Broker layer participate in the existing transaction if the web application makes the service layer participate in the transaction that initiates?

    Please let me know if i got it right.

    Thanks,
    -Mettu.

  4. #4
    Join Date
    Aug 2005
    Location
    Romania
    Posts
    10

    Default Re: Transaction Propagation

    Quote Originally Posted by mettus
    ... these are the layers i have in jar file
    Service layer - which is accessed by web applications
    - relies on Broker layer for actual database operations
    Broker Layer - does actual database access and update work.
    i defined the transactions at Broker level in the jar file.

    Now can the Broker layer participate in the existing transaction if the web application makes the service layer participate in the transaction that initiates?

    Please let me know if i got it right.

    Thanks,
    -Mettu.
    Here is how I see things:

    1. Make a POJO and wrap it around your Service layer.
    2. Make it transactional (very important).
    3. If your Broker layer throws an exception (e.g. SQLException) and it propagates up to your POJO, hence you don't catch it or rethrow it out of your POJO (or mark it as rolleBackOnly), transaction started by Spring AOP will be automatically rolledback therefore all participats to this transaction will be rolledback.

    On the other hand, If you don't get any exception out of your Service layer due to an exception from Broker layer (e.g. SQLException) and there is no way to know if JDBC operations from Broker layer failed, then I'm not sure how you can you make it participate to Spring transaction. It might be possible though if you're using DataSource's and somehow make it use a Spring defined DataSource.



    I hope that helps.

  5. #5
    Join Date
    Aug 2005
    Location
    Romania
    Posts
    10

    Default

    I forgot to mention about one other thing. If some other participant of the transaction causes a rollback, and you want your broker to also rollback, then I guess DataSource from Broker needs to be know by Transaction Manager (That of course in case that you're using DataSource and you're not doing "manual" commit)

Similar Threads

  1. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  2. Replies: 0
    Last Post: Jun 6th, 2005, 06:22 AM
  3. Replies: 3
    Last Post: May 16th, 2005, 07:04 AM
  4. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  5. Transaction pb Hibernate/MySQL
    By syluser in forum Data
    Replies: 2
    Last Post: Aug 28th, 2004, 02:40 PM

Posting Permissions

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