Calling session.getTransaction().begin()
doesn't make much sense as session.getTransaction()
will retrieve the transaction already in progress because it assumes that a transaction is in progress. You are basically saying, begin this transaction that should already be in progress.
session.beginTransaction()
will either begin a new Transaction if one isn't present, or it will use an existing transaction to begin the unit of work specified.
session.beginTransaction().begin()
== session.beginTransaction()
For more information I suggest you have a look at the Hibernate documentation for your version of Hibernate. You should only be dealing with the low levels of Hibernate like this if you are not using a TransactionManager
or you are using a JDBCTemplate
so have a think because messing with transactions in this way gets messy fast.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…