is a factory class that generates a session
Characteristics:
1.由Configuration通过加载配置文件创建该对象。
Sessionfactory factory = Config.buildsessionfactory ();
2.SessionFactory对象中保存了当前的数据库配置信息和所有映射关系以及预定义的SQL语句。同时,SessionFactory还负责维护Hibernate的二级缓存。
3. A sessionfactory instance corresponds to a database where an application obtains a session instance from that object.
4.SessionFactory is thread-safe, meaning that one instance of it can be shared by multiple threads being applied.
5.SessionFactory is heavyweight, meaning that it is not possible to create and destroy instances of it, and if only one database object needs to be created, just create a sessionfactory instance and complete it when the application is initialized.
6.SessionFactory requires a large cache to hold predefined SQL statements and entity mapping information, as well as a cache plug-in called Hibernate's Level two cache, which is shared by multiple threads.
Summarize:
Typically an application uses a sessionfactory, preferably at the time of application startup.
Sessionfactory Tool Class:
Importorg.hibernate.Session;Importorg.hibernate.SessionFactory;Importorg.hibernate.cfg.Configuration; Public classHibernateutils {Private Static FinalConfiguration CONFIG; Private Static Finalsessionfactory FACTORY; Static{ //Load configuration fileCONFIG =NewConfiguration (). Configure (); //Generate SessionfactoryFACTORY =config.buildsessionfactory (); } //Get Session Object Public StaticSession opensession () {returnfactory.opensession (); }}
Hibernate common interfaces and classes---sessionfactory classes and functions