Search code examples
hibernatedifferencerollbackbetween

Does it make sense to use Hibernate clear method and then rollback?


I want to know if there is any difference between hibernate's session.clear method and rollback() method? I understand that session.clear() will clear objects from the session and rollback() will rollback whole transaction. My question is will there be any performance difference if I use both methods together - first call session.clear() method and then call session.rollback() method?


Solution

  • In a typical transaction (pseudo-code):

    try {
        Begin Transaction;
        update + flush
        update + flush
        throw Ex
        commit;
    } catch Ex {
        rollback;
        // if you make rollback, clear is needed 
        clear;
    }