1, to the Java project, do database migration, will use the data script.
2. When hibernate is introduced, you can create a configuration file for a database table. Tables can be built automatically in the database based on the table's configuration file. ( the database should be pre-built, because hibernate will only build tables and not build libraries )
Steps:
1), add parameters in configuration file HIBERNATE.CFG.CML, configure related data source parameters and Pojo file
<property name= "Hbm2dll.auto" >update</property>
#update means that the table structure is automatically updated based on the model object, the database is automatically checked when Hibernate is started, and the table is automatically created if the table is missing, and columns are added automatically if a column is missing.
#create: When you start Hibernate, the original table is automatically deleted and all the tables are created, so the previous data will be lost after each startup.
#Create-drop: When you start hibernate, the table is automatically created and the corresponding table is automatically deleted when the program is closed. So at the end of the program, the table and the data no longer exist.
2), configure the Pojoname.hbm.xml configuration file, add hibernate-mapping
< Hibernate-mapping><class name= "Com.bean.Article" table= "article" catalog= "test" ><id name= "article_id" Type= "Java.lang.Integer" ><column name= "article_id" ></column><generator class= "Identity" > </generator></id><property name= "Outline" type= "java.lang.String" ><column name= "Outline" Length= "not-null=" false "></column></property><property name=" title "Type=" Java.lang.String " ><column name= "title" Length= "Not-null=" false "></column></property><many-to-one name=" Journal "class=" com.bean.Journal "column=" journal_id "not-null=" true "cascade=" all "></many-to-one><set Name= "Chapters" inverse= "true" cascade= "all" ><key column= "article_id" ></key><one-to-many class= " Com.bean.Chapter "></ONE-TO-MANY></SET></CLASS></HIBERNATE-MAPPING>
3. Set up a startup class
public class Inportdatabase {public static void Main (string[] args) { configuration cfg = new Configuration (). Con Figure (); Schemaexport export = new Schemaexport (CFG); Export.create (True, True);} }
The corresponding tables can be established in the database based on the configuration file.
Automatically build tables in Java based on hibernate profiles