Org. hibernate. cfg. Configuration
An instance represents an application.ProgramJava-SQL database ing complete set.Org. hibernate. cfg. Configuration
Is used to build an (immutable ))Org. hibernate. sessionfactory
. The ing definition is defined by different
The XML ing definition file is compiled.
You can instantiate it directly.Org. hibernate. cfg. Configuration
To get an instance and specify an XML ing definition file for it. If the ing definition file is in the classpath, useAddresource ()
. For example:
Configuration Cfg = New Configuration () . Addresource ( "Item. HBM. xml" ) . Addresource ( "Bid. HBM. xml" );
An alternative method (sometimes better) is to specify the ing class so that hibernate can help you find the ing definition file:
Configuration Cfg = New Configuration () . Addclass ( Org . Hibernate . Auction . Item . Class ) . Addclass ( Org . Hibernate . Auction . Bid . Class );
Hibernate will find the name in the classpath/Org/hibernate/auction/item. HBM. xml
And/Org/hibernate/auction/bid. HBM. xml
Ing definition file. This method eliminates any hard encoding of the file name (hardcoded ).
Org. hibernate. cfg. Configuration
> You can also specify configuration attributes. For example:
Configuration Cfg = New Configuration () . Addclass ( Org . Hibernate . Auction . Item . Class ) . Addclass ( Org . Hibernate . Auction . Bid . Class ) . Setproperty ( "Hibernate. dialect" , "Org. hibernate. dialect. mysqlinnodbdialect" ) . Setproperty ( "Hibernate. Connection. datasource" , "Java: COMP/ENV/jdbc/test" ) . Setproperty ( "Hibernate. order_updates" , "True" );
Of course, this is not the only way to pass the hibernate Configuration Attribute. Other optional methods include:
-
Upload oneJava. util. Properties
InstanceConfiguration. setproperties ()
.
-
set hibernate. properties
is placed under the root directory (root directory) of the classpath ).
-
using JAVA-dproperty = value
to set the system ( System
) attribute.
-
in hibernate. cfg. add the element