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

被折叠的 条评论
为什么被折叠?



