Summary on 20080626: hibernate configuration and hbm2ddl tool

来源:互联网 发布:unity3d 网页插件 编辑:程序博客网 时间:2024/05/22 15:06

xml file is actualy like the following format:

<!DOCTYPE hibernate-mapping

     PUBLIC "-//hibernate/hibernate mapping dtd 3.0//EN"

     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

in the hibernate configuration file hibernate.cfg.xml, when writing the mapping filesthe format should be:        <mapping resource="home/stronger/hibernate/**.hbm.xml"/>see, the path is actually seperated by '/', it's not the format of class path

hbm2ddl tool:in org.hibernate.tool.hbm2ddl package, there is class: SchemaExport, this class get the hibernate configuration and use the method create to create sql script and create the table in database, according to the mapping resource set.Ex:

Configuration config = new Configuration().configure();SchemaExport schema = new SchemaExport(config);schema.create(true,true);//schema.create(boolean sqlScript, boolean exportScript)//sqlScript: create sql script and show it in the console//export script: export the sql script to database and execute

 

原创粉丝点击