hibernate 之 hbm2ddl

   經過xxx.hbm.xml文件生成SQLhtml

 

import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class hbm2ddl {

    private static final Configuration CONFIGURATION;

    static {
        try {
            CONFIGURATION = new Configuration().
                    configure("hibernate.cfg.xml");
        } catch (Throwable ex) {
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static void main(String[] args) {
        SchemaExport export = new SchemaExport(CONFIGURATION);
        export.create(true, false);
    }
}

   注意:使用hbm2ddl工具時,必須在Hibernate的配置文件中設置dialect屬性,顯示指定底層數據庫的SQL方言。java

 

Class SchemaExport

Constructor Summary
SchemaExport(Configuration cfg)
          Create a schema exporter for the given Configuration
SchemaExport(Configuration cfg, Connection connection)
           
SchemaExport(Configuration cfg, Properties properties)
          Deprecated. properties may be specified via the Configuration object
SchemaExport(Configuration cfg, Settings settings)
          Create a schema exporter for the given Configuration and given settings
 

Method Summary
 void create(boolean script, boolean export)
          Run the schema creation script.
 void drop(boolean script, boolean export)
          Run the drop schema script.
 void execute(boolean script, boolean export, boolean justDrop, boolean justCreate)
           
 List getExceptions()
          Returns a List of all Exceptions which occured during the export.
static void main(String[] args)
           
 SchemaExport setDelimiter(String delimiter)
          Set the end of statement delimiter
 SchemaExport setFormat(boolean format)
           
 SchemaExport setHaltOnError(boolean haltOnError)
           
 SchemaExport setImportFile(String filename)
           
 SchemaExport setOutputFile(String filename)           Set an output filename.
相關文章
相關標籤/搜索