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 DTD
3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
 <property
name="connection.driver_class">
  com.mysql.jdbc.Driver
 </property>
 <property
name="connection.url">
  jdbc:mysql://localhost:3306/dang?useUnicode=true&amp;characterEncoding=utf8

</property>
 <property
name="connection.username">root</property>

<property
name="connection.password">123</property>

<!-- 显示SQL语句
-->
 <property
name="show_sql">true</property>

<property
name="format_sql">true</property>

<!-- 定义方言 -->
 <property
name="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 
-->
      
<column
name="id"></column>

<!--主键的生成策略 native可以适应多种数据库 
increment mysql自动增长策略  sequence oracle自动增长策略
-->
      
<generator
class="native"></generator>

</id>
   
<property name="name">
     
<column
name="name"></column>

</property>
   
   
<property name="pwd">
      
<column
name="pwd"></column>

</property>
   
<property name="age">
      
<column
name="age"></column>

</property>
 </class>

</hibernate-mapping>

上一篇:Android 开源项目PhotoView源码分析


下一篇:开源项目Telegram源码 Telegram for Android Source