6

ファイルをddl生成にマッピングするためのHibernateツールがあります。ddlからマッピングファイルなどに変換しますが、JPA注釈付きクラスから単純なDDLを生成するためのコマンドラインツールが見つかりません。

誰かがこれを行う簡単な方法を知っていますか?(AntまたはMavenの回避策を使用しない)

4

2 に答える 2

7

質問ですでに言及しているため、これが回避策と見なされるかどうかはわかりません。Hibernate Toolsを使用して、JPA アノテーション付きクラスから DDL を生成できます。hibernate ツールとそのクラスパスへの依存関係が必要なだけで、次のようなもので問題ありません。

<target name="schemaexport" description="Export schema to DDL file"
    depends="compile-jpa"> <!-- compile model classes before running hibernatetool -->

  <!-- task definition; project.class.path contains all necessary libs -->
  <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
      classpathref="project.class.path" />

  <hibernatetool destdir="export/db"> <!-- check that directory exists -->
    <jpaconfiguration persistenceunit="myPersistenceUnitName" />
    <classpath>
      <!--
          compiled model classes and other configuration files don't forget
          to put the parent directory of META-INF/persistence.xml here
      -->
    </classpath>
    <hbm2ddl outputfilename="schemaexport.sql" format="true"
        export="false" drop="true" />
  </hibernatetool>
</target>

一方、Webtools で Eclipse を使用していて、プロジェクト設定を正しく構成している場合は、右クリックしてコンテキスト メニューから[ DDL の生成] を選択するだけです。詳細については、Eclipse Dali の Web サイトを参照してください。

于 2009-01-31T00:20:59.837 に答える
4

ここでは、hibernate SchemaExport クラスを使用して必要なことを行う方法について説明します。前述の anttask メソッドと似ていますが、誰もが ant を使用しているわけではありません。このサンプル コードは、コマンドラインから直接実行できます。

http://jandrewthompson.blogspot.com/2009/10/how-to-generate-ddl-scripts-from.html

お役に立てれば。

于 2009-10-30T21:30:28.243 に答える