hibernate 之 hbm2ddl

   通过xxx.hbm.xml文件生成SQL

 

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方言。

 

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.

 

你可能感兴趣的:(Hibernate,hbm2ddl)