2008-11-11 61 views
5

有一些Hibernate工具用於將文件映射到ddl生成; DDL映射文件等,但我找不到任何命令行工具從JPA批註的類生成簡單的DDL。休眠JPA到DDL命令行工具

有沒有人知道一個簡單的方法來做到這一點? (不使用Ant或Maven解決方法)

回答

7

我不確定,這是否被認爲是解決方法,因爲您已經在您的問題中提及了它。您可以使用Hibernate Tools從JPA註釋類生成DDL。你只需要冬眠類路徑上的工具和它的依賴關係,並應罰款的東西,如以下:如果您使用的是Eclipse與Webtools的和正確配置的項目設置

<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> 

在另一方面,你可以只需右鍵單擊並選擇從上下文菜單中生成DDL。有關Eclipse Dali website的更多信息。