Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I couldnt find much information on this topic. Can someone explain me whats the Difference between Hibernate session.getTransaction().begin() vs session.beginTransaction() vs session.beginTransaction().begin()

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
581 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...