Note 1: Configure () can always find the configuration file. You do not need to specify the path for it.
Configuration Config = new configuration (); // configuration object config. addFile ("src \ main \ resources \ hibernate. cfg. XML "); // load the configuration file. In fact, config is optional. configure (); // no matter what project, the configuration file under the project directory will be found.
NOTE 2: There are non-basic types in the forward project, such as list <string>. Try not to map this attribute to the database and delete them in the corresponding configuration file.
Http://blog.csdn.net/xyzroundo/article/details/5612693
Method 1:In hibernate. cfg. set <property name = "hibernate. hbm2ddl. auto "> Update </property>, which is then deployed to the application server, such as Tomcat and other Web containers, so that the Web containers can be loaded to hibernate. cfg. XML to automatically generate database tables!
Note: How can I load a Web container to hibernate. cfg. xml? You can use the following method:
Integrate to springcontext as follows:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> </bean>
Springcontext can set listeners under Web. xml.
Method 2:Call the APIs in the hibernate core to compile a simple class for generating database tables:
Import Org. hibernate. cfg. configuration; import Org. hibernate. tool. hbm2ddl. schemaexport; public class exportdb {public static void main (string [] ARGs) {// read configuration file configuration CFG = new configuration (). configure ("/hibernate. cfg. XML "); // create the schemaexport object schemaexport export = new schemaexport (CFG); // create the database table export. create (True, true); // there is a serious problem. Delete the original data table before creating a new table }}
Run some classes to automatically generate database tables.