Configuration classes in Hibernate

Source: Internet
Author: User

The configuration class is used to manage the information of our configuration file, and through it we can manage the corresponding config document by creating a configuration instance, but usually we only create one configuration instance.
The following is a common code for creating an instance

Java code
Try {
New Configuration (). Configure (). Buildsessionfactory (); } Catch (Hibernateexception e) {

Throw New runtimeexception (e.getmessage,e); }

Here we see: To create a configuration, you can use the

New

What we have to understand here is that the configuration is the portal through which you get the config file.
The configuration can also be passed by specifying parameters:
See below:

New File ("C:\\hibernate.xml"New

At the same time, the configuration has some more important methods:

Take a look at the example below:

Properties Properties = Porperties.load ("a.properties"New

You can also specify a. hbm.xml file, here are several methods:

Take a look at the example below:

New Configuration (). addclass (Order.  Classnew configuration (). Addurl (configuration.  ClassNew

Here's a quick look at the Sessionfactory class
First look at the code

New

To illustrate, sessionfactory is thread-safe and can be called by multiple threads. In our actual development, we can construct a sessionfactory in the initialization section, for example, initialize a sessionfactory readonly constant in a public static class, and so on. It acts as a proxy for the data storage source. The factory model is used here. It is important to note that Sessionfactory is not lightweight, because in general, a project typically requires only one sessionfactory, and when you need to manipulate multiple databases, you can specify a sessionfactory for each database.

Reprinted from: "http://jnotnull.iteye.com/blog/153625"

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.