首页 > 代码库 > hibernate.cfg.xml配置文件和hbm.xml配置文件
hibernate.cfg.xml配置文件和hbm.xml配置文件
http://blog.sina.com.cn/s/blog_a7b8ab2801014m0e.html
hibernate.cfg.xml配置文件格式
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<propertyname="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<propertyname="connection.url">
jdbc:mysql://localhost:3306/dang?useUnicode=true&characterEncoding=utf8
</property>
<propertyname="connection.username">root</property>
<propertyname="connection.password">123</property>
<!-- 显示SQL语句-->
<propertyname="show_sql">true</property>
<propertyname="format_sql">true</property>
<!-- 定义方言 -->
<propertyname="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<mapping resource="entity/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
hbm.xml配置文件
<?xml version="1.0"encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--name 实体类的 包名+类名 table数据库的表名 -->
<class name="entity.User"table="t_user">
<!-- name对应实体类的属性id -->
<id name="id"type="integer">
<!-- name 对应数据库的列名id -->
<columnname="id"></column>
<!--主键的生成策略 native可以适应多种数据库 increment mysql自动增长策略 sequence oracle自动增长策略-->
<generatorclass="native"></generator>
</id>
<property name="name">
<columnname="name"></column>
</property>
<property name="pwd">
<columnname="pwd"></column>
</property>
<property name="age">
<columnname="age"></column>
</property>
</class>
</hibernate-mapping>
hibernate.cfg.xml配置文件和hbm.xml配置文件