Announcement Announcement Module
Collapse
No announcement yet.
Manage transactions in my own application Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Manage transactions in my own application

    I want to manage my own transactions, ie without web applications servers like JBoss or something like this. But I have some problem.
    Here is my code :

    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.P ROPAGATION_REQUIRED);
    // I've seen that the JdbcTemplate.update() method close the connection unless suppressClose is set to true
    ((SingleConnectionDataSource)getDataSource()).setS uppressClose(true);

    // _txManager is a bean associated with the bean declared in the spring-config.xml
    TransactionStatus status = _txManager.getTransaction(def);

    // This method updates my object, with using the method JdbcTemplate.update
    update(instanceObjectPath, "Description");

    // For test purpose, I want to rollback my transaction, but when I check information in the DB, update was done...
    _txManager.rollback(status);

    My question is : where is the mistake in this code ?

    Thanks

  • #2
    Seems fine - however, if you get an exception the rollback will never execute. What database are you using - maybe it doesn't support transactions (like mysql w/o innodb).
    Turn on logging and see what happens - moreover, you can use AbstractTransactionSpringContextTests (from org.springframework.test package) which offer good support for executing each test inside its own transaction which (by default) will be rolled back afterwards. You can read more about it in the reference documentation/

    Comment


    • #3
      [QUOTE=costin]Seems fine - however, if you get an exception the rollback will never execute. What database are you using - maybe it doesn't support transactions (like mysql w/o innodb).
      [QUOTE]
      I get no exception with this.
      In fact, I'm using mysql and tables are stored with MyISAM Engine. Perhaps it's the problem
      Turn on logging and see what happens - moreover, you can use AbstractTransactionSpringContextTests (from org.springframework.test package) which offer good support for executing each test inside its own transaction which (by default) will be rolled back afterwards. You can read more about it in the reference documentation/
      Thanks, I'll do this

      Comment


      • #4
        It works now, shame on me

        Comment

        Working...
        X