利用Hibernate配置文件反向生成数据库
2014-04-28 16:13
423 查看
1.Hibernate配置
文件hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="hbm2ddl.auto">update</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/test</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="myeclipse.connection.profile">test</property>
<mapping resource="com/test/fileInfo.hbm.xml"/>
</session-factory>
</hibernate-configuration>
注意:
(1)JDBC驱动为com.mysql.jdbc.Driver,可以根据所使用的库而更换。
(2)dialect
为数据库方言,根据所使用数据库不同而不同。这里是Mysql。
(3)jdbc.fetch_size和
jdbc.batch_size过小会降低性能,这里是建议设置。
(4)mapping文件根据文件所在路径而不同。这里是
放在WEB-INF/classes/com/test/目录下。
2.数据库映射配置FileInfo.hbm.xml
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.test">
<class name="FileInfo" table="t_fileInfo">
<id name="fileId" type="java.lang.Integer">
<column name="fileId" precision="6" scale="0" />
<generator class="native">
</generator>
</id>
<property name="fileName" column="fileName" />
<property name="fileTitle" column="fileTitle" />
<property name="fileAuthor" column="fileAuthor" />
<property name="fileStatus" column="fileStatus" />
<property name="fileIndexFlag" column="fileIndexFlag" />
<property name="fileKeyWord" column="fileKeyWord" />
<property name="directoryId" column="directoryId" />
<property name="fileFormat" column="fileFormat" />
<property name="fileSize" column="fileSize" />
<property name="filePath" column="filePath" />
<property name="creatDate" column="creatDate" />
<property name="createAccountsId" column="createAccountsId" />
<property name="createAccountsName" column="createAccountsName" />
<property name="verifyAccountsId" column="verifyAccountsId" />
<property name="templateId" column="templateId" />
<property name="remark" column="remark" />
<property name="content" column="content" />
</class>
</hibernate-mapping>
3.初始化数据库类
package com.test; import org.hibernate.cfg.Configuration; import org.hibernate.tool.hbm2ddl.SchemaExport; public class ExportDB { public static void main(String[] args) { // 读取hibernate.cfg.xml文件 Configuration cfg = new Configuration().configure(); SchemaExport export = new SchemaExport(cfg); export.create(true, true); } }
相关文章推荐
- Hibernate中利用配置文件(hbm)自动生成数据库表
- 利用Hibernate配置文件生成数据库
- 利用Hibernate配置文件生成数据库
- 如何利用Hibernate配置文件生成数据库
- 在Spring中利用Hibernate的配置文件生成数据库表
- Hibernate:利用配置文件生成数据库
- 利用Hibernate配置文件生成数据库
- 用HIBERNATE反向工程生成POJO后配置文件没有更新的问题
- 在MyEclipse中利用XDoclet自动生成Hibernate配置和映射文件
- MyEclipse配置Hibernate/MyEclipse反向工程从数据表生成POJO和对象关系映射文件(以及HibernateSessionFactory)
- hibernate通过配置文件生成数据库信息
- hibernate之利用配置文件和annotation往数据库里插入数据
- java连接oracle数据库(利用MyEclipse开发工具反向生成 bean与配置文件)
- 根据hibernate配置文件生成数据库建表脚本
- 如何根据hibernate的实体类和实体类配置文件生成数据库的表
- 利用MyEclipse从数据库反向生成实体类之Hibernate方式
- 利用hibernate配置文件逆向映射数据库表
- hibernate 根据配置文件自动生成数据库表
- 使用myeclipse从数据库反射生成hibernate实体类和配置文件
- Hibernate配置文件中hiberante.hbm2ddl.auto四个参数的配置----牛逼。可以自动生成数据库。