Announcement Announcement Module
Collapse
No announcement yet.
Spring Transactional is not working with plain JDBC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Transactional is not working with plain JDBC

    Hi,

    I'm facing problem with @Transactional when using with plain JDBC.

    The components I have written

    1. Written a service with one service method which is transactional (@Transactional)
    2. One bean
    3. DAO interface and the implementation class
    4. One class to get the connection from the data source (of type org.apache.commons.dbcp.BasicDataSource) configured at the spring configuration file.
    5. Test class

    I Tried both

    1. Annotation driven by using @Transsactional and the corresponding configuration settings at xml file
    2. AOP configuring using declarative approach in the xml level.


    1. Calling the service class method from the test class.
    2. The service method calls the DAO class methods which interacts with the DB by getting the connection from the data source configured at spring XML file.

    From the service method I'm calling two DAO methods (1. DAOinsert() and 2. DAOget() ) and in between written a code to throw ArthimeticException to test the transaction rollback. But the first db operation which is an insert is not getting rollback even the ArthimeticException is thrown.

    @Transactional(rollbackFor = {ArithmeticException.class})
    Service method(){
    DAOinsert();
    int i = 10/0; //ArthimeticException
    DAOget();
    }

    The first operation is not getting rollback( the record is getting inserted into the table instead of rollback)

    It is working fine when I use JDBCTemplate instead of JDBC.

    Please help me in fixing this issue.

  • #2
    If it is working with JDBCTemplate, for me it sounds like your spring configuration is all right (right transaction manager, right db connection pooling etc.).

    I have not fully understand what (plain) JDBC means to you. I guess that you somehow circumvent the transaction manager in this case.

    Comment

    Working...
    X