Version 4

    Lazy Autocommit


    JBoss takes advantage of an obvious (though undocmented)

    performance optimization done by all databases.


    // do work
    connection.commit(); // ends the previous transaction


    We should do the following, but that would typically involve

    two network requests for poorly implemented jdbc drivers

    // When the user does connection.close()
    // At the next setAutoCommit(false) when the user asks for the connection again.


    But we actually do

    // *nothing*


    Followed by the next transaction

    // do work


    Databases don't automatically start a new/next transaction after

    a connection.commit() because this would be a waste if the

    user is just going to do connection.close() straight away.

    They start the next transaction at the first "do work".


    In fact, JBoss's jdbc wrapper uses the same technique (for the same

    reason) with the checkTransaction() done during createStatement(), etc.