Hibernate common interfaces and classes---sessionfactory classes and functions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.