In hibernate, there are two ways to build a sessionfactory from the configuration that can be used One is to provide a Hibernate.cfg.xml profile for the configuration, and the other is to provide a hibernate.properties configuration file.
1. Provide the Hibernate.cfg.xml configuration file:
static {
Configuration Config=null;
try {
Config = new Configuration (). Configure ();//using Configure () method to load the default Hibernate.cfg.xml configuration file because the configuration file already contains database mapping information, so you do not need to use the AddClass method to load the mapping files for each class file
} catch (Hibernateexception E1) {
E1.printstacktrace ();
}
try {
Sessionfactory=config.buildsessionfactory ();
} catch (Exception e) {
E.printstacktrace ();
}
}
2. Provide the hibernate.properties configuration file:
static {
Configuration Config=null;
Config = new Configuration ();//Because the new one configuartion loads the Hibernate.proprties file by default, you do not need to call the Configure method.
try {
Config.addclass (Manager.class);//Because there is no mapping information in the Hibernate.properties file, you need to call the AddClass method to explicitly load the mapping file for the class file
Sessionfactory=config.buildsessionfactory ();
} catch (Exception e) {
E.printstacktrace ();
}
}
If the method uses error, error message will be various, I in this problem after two weeks of trouble finally solved!!!
About the configuration in hibernate