关闭

hibernate 采用映射文件配置

标签: hibernate xml
148人阅读 评论(0) 收藏 举报
分类:

hibernate.cfg.xml

 <?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE hibernate-configuration PUBLIC  
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">  
          
<hibernate-configuration>  
    <session-factory>  
   <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>//mysql方言
   <property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>//mysql驱动
   <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test?serverTimezone=GMT</property>
   <property name="connection.characterEncoding">utf-8</property> 
   <property name="hibernate.connection.username">root</property>
   <property name="hibernate.connection.password">admin</property>    
    <property name="show_sql">true</property>   //控制台显示sql语句
    <property name="hbm2ddl.auto">update</property>//更新数据库表
    <mapping  resource="cn/model/Tourist.hbm.xml"/> //配置的映射表
    </session-factory>  
</hibernate-configuration>  

serverTimezone=GMT时区


Tourist.hbm.xml和Tourist类同一包下

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
  "-//Hibernate/Hibernate Mapping DTD//EN"
  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">


<hibernate-mapping>
<class name="cn.model.Tourist" table="TOURIST">
<meta attribute="class-description">
This class contains the employee detail.
</meta>
<id name="id" type="int" column="id">
<generator class="native" />
</id>
<property name="name" column="name" type="string" />
<property name="phone" column="phone" type="string" />
<property name="qq" column="qq" type="string" />
<property name="password" column="password" type="string" />
<property name="temp" column="temp" type="int" />
</class>
</hibernate-mapping>


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:11819次
    • 积分:397
    • 等级:
    • 排名:千里之外
    • 原创:29篇
    • 转载:2篇
    • 译文:0篇
    • 评论:0条