Results 1 to 5 of 5

Thread: Transactions in Spring

  1. #1
    Join Date
    Dec 2005
    Posts
    6

    Default Transactions in Spring

    Hi,

    I am new to the spring framework. I am trying to modify the code to use the spring framework.
    The original code is

    ----------------------------------------
    Connection conn;
    conn.setAutoCommit(false);
    addRecord(); //adds arecord into table
    updateTable(); // updates another table
    conn.commit();
    autoCommit = true;
    conn.setAutoCommit(autoCommit);
    -------------------------------------------

    I am using the Spring BeanFactory to get the connection..
    Could anyone help me regarding this.. It would be a great help

    Thanks

  2. #2
    Join Date
    Nov 2005
    Posts
    24

    Default

    Hi

    Hibernate becomes a bit different when used with spring . And A LOT easyer in the end .

    This would be a good place to start . You can also find tons of examples in most of the posts in this section

    good luck

  3. #3
    Join Date
    Dec 2005
    Posts
    6

    Default

    Thanks for the reply. But I was looking for something with plain JDBC and Spring. Could someone post an example.

    Thank you

  4. #4
    Join Date
    Nov 2005
    Posts
    24

    Default

    oh sorry , i got ahead of myself , and thought you were using hibernate , must have been too late at night

    well hibernate was chapter 12 , so if you want to step backwards to jdbc here's chapter 11

  5. #5
    Join Date
    Dec 2005
    Posts
    6

    Default

    TransactionTemplate tt = new TransactionTemplate();
    tt.execute(new TransactionCallbackWithoutResult()
    {
    protected void doInTransactionWithoutResult(TransactionStatus status)
    {
    updateRecord();
    updateDifferentRecord();
    }});


    I have written the above code...the two updates have to be done in one transaction.. I am not sure whether this is the correct code....I was concerned about the begin and commit transaction methods in the previous code which are not there in this code....It would be of great help if someone could correct me if the abovce code is wrong, and also please let me know how the begin and commit transactions are handled in the above code..


    Thanks

Posting Permissions

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