Run hbm2java and hbm2ddl tools, and hbm2javahbm2ddl

Source: Internet
Author: User

Run hbm2java and hbm2ddl tools, and hbm2javahbm2ddl

The following content is organized from the second edition of hibernate


Hibernate provides a conversion tool from the ing file to the Java source code, named hbm2java, which can be run using ANT.

<span style="font-size:18px;"><target name="codegen" depends="prepare">    <taskdef name="hbm2javaTask"                    classname="org.hibernate.tool.ant.HibernateToolTask"                    classpathref="project.class.path" />    

The preceding Code defines an hbm2javaTask task. Its destdir attribute specifies that the Java source file is stored in $ {source. in the root directory (src subdirectory), the <configuration> sub-element specifies that the configuration file of Hibernate is classes/hibernate. cfg. xml. The hibernate. cfg. xml file is a configuration file in XML format. The

<Hbm2java> A task can also contain two attributes: "jdk5" and "ejb3", which are used as follows:

<Hbm2java jdk5 = "true | false" ejb3 = "true | false">

<Hnm2java> the jdk5 attribute of the task specifies whether the generated Source Code contains the JDK5 syntax. The ejb3 attribute specifies whether the generated Java Source Code contains the features of ejb3, the default values of these two attributes are false.


Hibernate provides a conversion tool from the ing file to the database Schema, named hbm2ddl. When using hbm2ddl, you must set Hibernate in the hibernate configuration file. the dialect attribute displays the SQL dialect of the specified 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 preceding Code defines an hbm2ddlTask. Its destdir attribute specifies that the generated DDL script file is stored in $ {schema. in the dir} directory (schema subdirectory), the <configuration> sub-element specifies that the configuration file of Hibernate is classes/hibernate. cfg. xml. The


<Hbm2ddl> task attributes

If export is true, the generated DDL script is executed in the database. The default value is true.

If drop is true, a DDL script is generated to delete tables in the database. The default value is true.

If "create" is set to "true", the DDL script for creating tables in the database is generated. The default value is true.

Outputfilename specifies the file to store the DDL script

If the value of update is true, the DDL statement used to incrementally update the database is generated compared with the existing database and the ing file. It is worth noting that this incremental update cannot be used in databases that are officially put into operation. Because it is not very robust at present, it cannot ensure the generation of accurate incremental update DDL, nor can it ensure that the underlying database can smoothly execute incremental update DDL. The default value is false.

If haltonerror is true, the ANT project will be terminated when an error occurs. The default value is false.

Format: sets the format of SQL statements in DDL scripts.

Delimiter sets the row Terminator for the DDL script

If the console value is true, a DDL script is generated on the console. The default value is true.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.