﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-lyc8-文章分类-Hibernate</title><link>http://www.blogjava.net/lyc8/category/23653.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 29 Jun 2007 02:34:27 GMT</lastBuildDate><pubDate>Fri, 29 Jun 2007 02:34:27 GMT</pubDate><ttl>60</ttl><item><title>HibernateTools工具使用</title><link>http://www.blogjava.net/lyc8/articles/126821.html</link><dc:creator>lyc</dc:creator><author>lyc</author><pubDate>Thu, 28 Jun 2007 07:16:00 GMT</pubDate><guid>http://www.blogjava.net/lyc8/articles/126821.html</guid><wfw:comment>http://www.blogjava.net/lyc8/comments/126821.html</wfw:comment><comments>http://www.blogjava.net/lyc8/articles/126821.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/lyc8/comments/commentRss/126821.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/lyc8/services/trackbacks/126821.html</trackback:ping><description><![CDATA[jar包:<br>HibernateTools-3.2.0.beta9a\plugins\org.hibernate.eclipse_3.2.0.beta9a\lib\tools\hibernate-tools.jar<br><br>帮助文档:<br>HibernateTools-3.2.0.beta9a\plugins\org.hibernate.eclipse.help_3.2.0.beta9a\doc.zip\html\tools\ant\en\html_single\index.html<br><br>使用工具:<br>hbm2java<br>hbm2ddl<br><br>hbm2java的属性介绍:<br>
<pre class="programlisting">&lt;hbm2ddl<br> export="true|false"                                  <span class="co">(1)</span><br> update="true|false"                                  <span class="co">(2)</span><br> drop="true|false"                                    <span class="co">(3)</span><br> create="true|false"                                  <span class="co">(4)</span><br> outputfilename="filename.ddl"                        <span class="co">(5)</span><br> delimiter=";"                                        <span class="co">(6)</span><br> format="true|false"                                  <span class="co">(7)</span><span class="co"></span><br> haltonerror="true|false"			      <span class="co">(8)</span><br>&gt;</pre>
<table summary="Callout list" border="0">
    <tbody>
        <tr>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top" width="5%">(1)</td>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top">
            <p>export (default: true): Execute the generated statements
            against the database</p>
            </td>
        </tr>
        <tr>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top" width="5%">(2)</td>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top">
            <p>update(default: false): Try and create an update script
            representing the "delta" between what is in the database and
            what the mappings specify. Ignores create/update attributes.
            (<span class="emphasis"><em>Do *not* use against production databases, no
            guarantees at all that the proper delta can be generated nor
            that the underlying database can actually execute the needed
            operations</em></span>)</p>
            </td>
        </tr>
        <tr>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top" width="5%">(3)</td>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top">
            <p>drop (default: false): Output will contain drop
            statements for the tables, indices &amp; constraints</p>
            </td>
        </tr>
        <tr>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top" width="5%">(4)</td>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top">
            <p>create (default: true): Output will contain create
            statements for the tables, indices &amp; constraints</p>
            </td>
        </tr>
        <tr>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top" width="5%">(5)</td>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top">
            <p>outputfilename (Optional): If specified the statements
            will be dumped to this file.</p>
            </td>
        </tr>
        <tr>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top" width="5%">(6)</td>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top">
            <p>delimiter (default: ";"): What delimter to use to
            separate statements</p>
            </td>
        </tr>
        <tr>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top" width="5%">(7)</td>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top">
            <p>format (default: false): Apply basic formatting to the
            statements.</p>
            </td>
        </tr>
        <tr>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top" width="5%">(8)</td>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top">
            <p>haltonerror (default: false): Halt build process if an error occurs.</p>
            </td>
        </tr>
    </tbody>
</table>
<br><br>hbm2java的属性介绍:<br>
<pre class="programlisting">&lt;hbm2java<br> jdk5="true|false"                                    <span class="co">(1)</span><br> ejb3="true|false"                                    <span class="co">(2)</span><br>&gt;</pre>
<table summary="Callout list" border="0">
    <tbody>
        <tr>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top" width="5%">(1)</td>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top">
            <p>jdk (default: false): Code will contain JDK 5 constructs
            such as generics and static imports</p>
            </td>
        </tr>
        <tr>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top" width="5%">(2)</td>
            <td style="border: 1px dashed #7f7c75;" align="left" valign="top">
            <p>ejb3 (default: false): Code will contain EJB 3 features,
            e.g. using annotations from javax.persistence and
            org.hibernate.annotations</p>
            </td>
        </tr>
    </tbody>
</table>
<br><br><br>示例:<br>build.xml(用ant运行):<br>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br>&lt;project name="Hibernate" default="help" basedir="."&gt;<br>&nbsp;&nbsp;&nbsp; &lt;!--源文件目录&nbsp; --&gt;<br>&nbsp;&nbsp;&nbsp; &lt;property name="source.root" value="src"/&gt;<br>&nbsp;&nbsp;&nbsp; &lt;!--类文件目录&nbsp; --&gt;<br>&nbsp;&nbsp;&nbsp; &lt;property name="class.root" value="WebRoot/WEB-INF/classes"/&gt;<br>&nbsp;&nbsp;&nbsp; &lt;!--库文件目录&nbsp; --&gt;<br>&nbsp;&nbsp;&nbsp; &lt;property name="lib.dir" value="WebRoot/WEB-INF/lib"/&gt;<br>&nbsp;&nbsp;&nbsp; &lt;!--ddl存放目录--&gt;<br>&nbsp;&nbsp;&nbsp; &lt;property name="schema.dir" value="schema"/&gt;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &lt;!--类路径&nbsp; --&gt;<br>&nbsp;&nbsp;&nbsp; &lt;path id="project.class.path"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;!--包含自己当地的classes&nbsp; --&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;pathelement location="${class.root}"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;!--包含库里的jars--&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;fileset dir="${lib.dir}"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;include name="*.jar"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/fileset&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/path&gt;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &lt;target name="help"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;echo message="利用工具开发hibernate"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;echo message="---------------------"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;echo message="有以下任务供选择:"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;echo message=""/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;echo message="generate-code-schema --&gt; 运行hbm2java,hbm2ddl,利用hbm.xml文件生成Jopo类和数据表"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;echo message="generate-code --&gt; 运行hbm2java,利用hbm.xml文件生成Jopo类"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;echo message="generate-schema --&gt; 运行hbm2ddl,利用hbm.xml文件生成数据表"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;echo message="generate-schema2 --&gt; 运行schemaExport,利用hbm.xml文件生成数据表"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;echo message=""/&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/target&gt;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &lt;target name="generate-code-schema" description="用hibernatetool包的HibernateTool利用hbm同时导出JOPO和ddl"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="project.class.path"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;hibernatetool destdir="${source.root}"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;configuration configurationfile="${class.root}/hibernate.cfg.xml"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;fileset dir="${source.root}/"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;include name="**/*.hbm.xml"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;!-- &lt;exclude name="**/*test.hbm.xml"/&gt; --&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/fileset&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/configuration&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;hbm2java/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/hibernatetool&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;hibernatetool destdir="${schema.dir}"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;configuration configurationfile="${class.root}/hibernate.cfg.xml"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;fileset dir="${source.root}/"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;include name="**/*.hbm.xml"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;!-- &lt;exclude name="**/*test.hbm.xml"/&gt; --&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/fileset&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/configuration&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;hbm2ddl outputfilename="db.sql"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/hibernatetool&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;/target&gt;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &lt;target name="generate-code" description="用hibernatetool包的HibernateTool利用hbm导出JOPO"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="project.class.path"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;hibernatetool destdir="${source.root}"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;configuration configurationfile="${class.root}/hibernate.cfg.xml"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;fileset dir="${source.root}/"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;include name="**/*.hbm.xml"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;!-- &lt;exclude name="**/*test.hbm.xml"/&gt; --&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/fileset&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/configuration&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;hbm2java/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/hibernatetool&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;/target&gt;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &lt;target name="generate-schema" description="用hibernatetool包的HibernateTool利用hbm导出ddl"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="project.class.path"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;hibernatetool destdir="${schema.dir}"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;configuration configurationfile="${class.root}/hibernate.cfg.xml"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;fileset dir="${source.root}/"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;include name="**/*.hbm.xml"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &lt;!-- &lt;exclude name="**/*test.hbm.xml"/&gt; --&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/fileset&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/configuration&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;hbm2ddl outputfilename="db.sql"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/hibernatetool&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;/target&gt;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &lt;target name="generate-schema2" description="用hibernate包自带的SchemaExport利用hbm文件导出ddl"&gt;<br>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;taskdef name="schemaexport" classname="org.hibernate.tool.hbm2ddl.SchemaExportTask" classpathref="project.class.path"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;schemaexport output="${schema.dir}/db.sql" config="${class.root}/hibernate.cfg.xml"<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; quiet="no" text="no" drop="no" delimiter=";"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;fileset dir="${source.root}/cn/hibernate/or"&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;include name="**/*.hbm.xml"/&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/fileset&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;/schemaexport&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;/target&gt;<br>&lt;/project&gt;<br><br>      <img src ="http://www.blogjava.net/lyc8/aggbug/126821.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/lyc8/" target="_blank">lyc</a> 2007-06-28 15:16 <a href="http://www.blogjava.net/lyc8/articles/126821.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>