Spring, Hibernate, MySQL - How Transaction Works - Conclusion / Questions **

I work with Spring Framework 3.0.5, Hibernate 3.6, and MySQL Server 5.1. I have some questions regarding transaction management in general. I personally use declarative transaction management from spring. It would be great if you answered my yes / no questions (or right / wrong) and, if necessary, give a brief explanation. It would be nice if several people would answer, if there were different opinions. Thank: -)

1) . You would say that these proposals are true: the DBMS is responsible for the overall implementation of transactions and their behavior.

1) B) Perhaps it would be better to say: the DBMS is responsible for the overall implementation of transactions and database behavior (for example, when a transaction is rolled back).

2) Hibernate just uses a database connection. It needs transactions, but it does not configure any (!) Settings regarding transactions and their behavior.

3) But: in order to work with transactions, Hibernate needs to KNOW where the transactions begin, and they need to be canceled.

4) Can Hibernate also know what happens if the rollback occurs? I think not, because it should be defined in the DBMS. (this means: which tables should be locked, which database operations should be canceled, etc.)?

5) 3) .

6) , Hibernate (3)), .

7) , spring.

8) Spring . . , .

9) Spring ,

10) Spring - , ? , , Spring , ? ...

: -)


[EDIT] duffymo, , 8 , . .

@duffymo

, :

  • , , (!) , , , ? (PlatformTransactionManager), , , . , , , ? , , (1B)

  • . , : -)

  • ? , ? "start tx, commit...",

  • . , . , , arent, , , , . , , - try/catch-block, . , , , . try/catch - ?

  • , . Spring . Spring , , transman. ... .. . , "Hibernate == programtic", Hibernate , . , , hibernate ITSELF.

  • , JDBC. , , . - , , Im ( ), .:-) , .

  • Hibernate , , spring. , " , ". (, tx, , ). , Spring , . , . , : -)

  • ok, . , tx ..

  • ..

  • : -)

, . , , . :-) !: -)

+5
2

:

  • / , , . Spring, JDBC , , , .
  • Hibernate .
  • .
  • Hibernate , ; , , .
  • Hibernate == ; Spring == .
  • . JDBC, . . (, . , ?)
  • - .
  • .
  • Spring , .
  • , .

? .

JDBC. , Java-, JDBC , Hibernate Spring. :

// prototypical write operation
public void update(Connection connection) throws SQLException
{
    connection.setAutoCommit(false);
    try
    {
        // SQL logic here
        connection.commit();  // if you get here, success
    } 
    catch (SQLException e)
    {
        try { if (connection != null) connection.rollback(); } catch (SQLException e) {}
        // might do some other things here (logging, etc.)
        // sql error codes will tell you why; spring translates these for you.
    }
    finally
    {
        // close statements here in individual try/catch blocks.
    }
}
+5
  • , Hibernate, / ,
  • , Hibernate ,
  • right, Spring

, , Spring docs IBM developerWorks

+1

All Articles