炳旭的博客

奋斗在前线

hibernate 采用映射文件配置

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>


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27474851/article/details/52346453
文章标签: hibernate xml
个人分类: Hibernate
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

hibernate 采用映射文件配置

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭