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"