Hibernate closed instance resolution about session

This paper mainly studies the closing of session in Hibernate, as follows.

1. What is the difference between getcurrentsession() and opensession()?

2. Use getcurrentsession() in hibernate cfg. Add the following configuration to the XML file:

thread

jta

What are the differences and associations between opensession() and getcurrentsession()?

When the sessionfactory is started, hibernate will create the corresponding currentsessioncontext according to the configuration. When getcurrentsession() is called, the method actually executed is currentsessioncontext currentSession() 。 When currentsession() is executed, if the current session is empty, currentsession will call opensession of sessionfactory. Therefore, getcurrentsession () is a better method for Java EE to obtain session.

Many times, session is close(); The reason is that you are in hibernate cfg. XML is set

The system is in commit(); After the execution, the session is closed. At this time, if you manually close the session again, of course, an error will be prompted

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>