Summary on 20080626: hibernate configuration and hbm2ddl tool

本文介绍了Hibernate配置文件的正确格式及映射文件的路径设置方式,并详细解释了如何使用SchemaExport类来根据Hibernate配置生成数据库表结构。

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值