Announcement Announcement Module
Collapse
No announcement yet.
Setting transaction timeout with NamedParameterJdbcTemplate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting transaction timeout with NamedParameterJdbcTemplate

    I am using the NamedParameterJdbcTemplate for query/update data, but I have encountered the problem which is in my system, some tables will be locked by other for updating, if I using the NamedParameterJdbcTemplate to update the table, the transaction will be hold until the other commit/rollback the transaction. In order to solve this problem, I would like to add some timeout configuration for this (as I know JdbcTemplate can set the timeout configuration and DataSourceUtils.applyTransactionTimeout may be also work). Can anyone advise what I can do to apply the transaction timeout in NamedParameterJdbcTemplate.


    Many Thanks.

  • #2
    I use this routine....


    ...



    DefaultTransactionDefinition txd = new DefaultTransactionDefinition();
    txd.setName("EventiUtenteDAO.insert");
    txd.setPropagationBehavior(TransactionDefinition.P ROPAGATION_REQUIRED);

    txd.setIsolationLevel(TransactionDefinition.ISOLAT ION_READ_COMMITTED);
    txd.setTimeout(50);

    DataSourceTransactionManager txManager = new DataSourceTransactionManager(getDataSource());
    TransactionStatus status = txManager.getTransaction(txd);
    try
    {
    ....sql statement....
    }
    catch (DataAccessException ex)
    {
    txManager.rollback(status);
    throw ex;
    }
    txManager.commit(status);
    }

    Comment

    Working...
    X