Announcement Announcement Module
Collapse
No announcement yet.
Transactions in Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring
    started a topic Transactions in Spring

    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

  • spring
    replied
    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

    Leave a comment:


  • cosmin
    replied
    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

    Leave a comment:


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

    Thank you

    Leave a comment:


  • cosmin
    replied
    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

    Leave a comment:

Working...
X