Hibernate has a new version and some content is being updated.
Package Test.hibernate.hbmsessionmanage;import Org.hibernate.session;import Org.hibernate.sessionfactory;import Org.hibernate.cfg.configuration;import Org.junit.test;public class App {private static sessionfactory Sessionfactory = New Configuration ()//.configure ("Test/hibernate/hbmsessionmanage/myhibernate.cfg.xml")//.buildsessionfactory () */* * To use the Sessionfactory.getcurrentsession () method * You need to configure the Current_session_context_class entry in the Hibernate master configuration file */@Testpublic void Testsession () throws Exception {//session Session1 = Sessionfactory.getcurrentsession ();//Session Session2 = Sessio Nfactory.getcurrentsession ();//Session Session1 = Sessionfactory.opensession ();//Session Session2 = Sessionfactory.opensession (); Session Session1 = Sessionfactory.opensession (); Session Session2 = Sessionfactory.getcurrentsession (); SYSTEM.OUT.PRINTLN (Session1! = null); System.out.println (Session1 = = Session2);} /* * Getcurrentsession (): Specifies that the context (such as thread) looks for a binding session object, returns if any; * if not, create one and bind, then return opensession (): Just * open a newSession, do not bind and find operation */@Testpublic void Testsessionclose () throws Exception {Session Session2 = Sessionfactory.getcurrentsession (); Session2.begintransaction (); System.out.println ("xxxxxxxxxxxxxxxxxxxxxx"); Session2.gettransaction (). commit ();//Session2.close ();}}
Under the same name package
<! DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "http://www.hibernate.org/ Dtd/hibernate-configuration-3.0.dtd ">
Cond
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. If you want to reprint, please specify the source: Http://blog.csdn.net/lindonglian
Hibernate (13) Session Management