Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
586 views
in Technique[技术] by (71.8m points)

java - Difference between Hibernate session.getTransaction().begin() vs session.beginTransaction()

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...