The following is organized from the second edition of Master Hibernate
Hibernate provides a conversion tool from the mapping file to the Java source code, called the Hbm2java tool, which can be used to run 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 attribute specifies that the Java source file is stored in the ${source.root} directory (that is, the SRC subdirectory),<configuration> The child element specifies that hibernate's configuration file is Classes/hibernate.cfg.xml. The Hibernate.cfg.xml file is a configuration file in XML format. 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 that specifies the underlying database, because 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 whose Destdir property specifies that the generated DDL script file is stored in the ${schema.dir} directory (that is, the schema subdirectory),<configuration> The child element specifies that hibernate's configuration file is Classes/hibernate.cfg.xml. Hbm2ddltask Task Heavy
Export If True, indicates that the generated DDL script is executed in the database. Default is True
Drop If True, the DDL script that deletes the table in the database is generated. Default is True
Create if True, the DDL script that creates the tables in the database is generated. Default is True
OutputFileName Specifies the file that holds the DDL script
Update If True, indicates that the DDL used to incrementally update the database is generated by comparing the existing database with the mapping file. It is important to note that this incremental update is used in databases that cannot be formally put into operation. Because it is not very robust at this time, it is not guaranteed to generate accurate incremental update DDL, nor does it guarantee that the underlying database can perform incremental update DDL successfully. The default value is False
Haltonerror If True, indicates that an ant project will be 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
Console If True, indicates that the generated DDL script will be displayed in the console. The default value is True
Run the Hbm2java tool and the HBM2DDL tool