The following is compiled from the second edition of Master Hibernate
Hibernate provides a conversion tool from the mapping file to the Java source, called the Hbm2java tool, which can be used to execute it using the Ant tool.
<span style= "FONT-SIZE:18PX;" ><target name= "CodeGen" depends= "Prepare" > <taskdef name= "Hbm2javatask" classname= " Org.hibernate.tool.ant.HibernateToolTask " classpathref=" Project.class.path "/>
The above code defines a hbm2javatask task whose Destdir property specifies that the Java source file is stored in the ${source.root} folder (that is, the Src subfolder). The <configuration> child element specifies that the configuration file for Hibernate is Classes/hibernate.cfg.xml.The Hibernate.cfg.xml file is a configuration file in XML format.
The Hbm2javatask task heavy
The
The Jdk5 property of the
Hibernate provides a conversion tool from the mapping file to the database schema, called the Hbm2ddl tool, when using the Hbm2ddl tool. The Hibernate.dialect property must be set in Hibernate's configuration file to display the SQL dialect for the specified underlying database, since the HBM2DDL tool generates the corresponding database schema based on the SQL dialect of the database.
<span style= "FONT-SIZE:18PX;" ><target name= "schema" depends= "compile" > <taskdef name= "Hbm2javatask" classname= " Org.hibernate.tool.ant.HibernateToolTask " classpathref=" Project.class.path "/>
The above code defines a hbm2ddltask task. Its Destdir property specifies that the generated DDL script file is stored under the ${schema.dir} folder (that is, the schema subfolder). The <configuration> child element specifies that the configuration file for Hibernate is Classes/hibernate.cfg.xml.Hbm2ddltask Task Heavy
Export assumes true to indicate that the generated DDL script will be run in the database. The default feels True
The drop hypothesis is true, which means that the DDL script that deletes the tables in the database is generated. The default feels True
Create is assumed to be true. Indicates that a DDL script is generated that creates tables in the database. The default feels True
OutputFileName Specifies the file that holds the DDL script
Update is assumed to be true. Indicates that the DDL used to incrementally update the database is generated against the existing database and the mapping file. It is important to note that such incremental updates are used in databases that cannot be formally put into execution. Since it is not very robust at the moment, there is no guarantee that an accurate incremental update of the DDL will be generated or that the underlying database will be able to perform incremental update DDL successfully. The default value is False
Haltonerror is assumed to be true, indicating that execution Antproject is terminated when an error is encountered. The default value is False
format settings for SQL statements in DDL scripts
Delimiter to set the line terminator for a DDL script
The console assumes true to indicate that the generated DDL script will be displayed in the console. The default value is True
Execute Hbm2java tools and HBM2DDL Tools