码迷,mamicode.com
首页 > Web开发 > 详细

hibernate.cfg.xml

时间:2017-07-12 10:26:39      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:其他   lan   hbm   org   类型   ati   oct   赋值   actor   

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="connection.username">root</property>
        <property name="connection.password">xxx</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/hibernate_demo</property>
<!--选择数据库方言-->        
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!--是否在console输出sql语句-->
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
<!--update用于更新数据库表,常见create:如果数据库存在该表先删除再重建-->
        <property name="hbm2ddl.auto">update</property>
        <mapping resource="Students.hbm.xml" />
    </session-factory>
</hibernate-configuration>

Students.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">
<!-- Generated 2017-7-10 22:35:01 by Hibernate Tools 3.5.0.Final -->
<hibernate-mapping>
<!-- class name是package.classname -->
    <class name="xml_onetomany.Students" table="STUDENTS">
        <id name="sid" type="int">
            <column name="SID" />
<!--assigned:初始化对象的时候SID要手动赋值,否则int默认为0,其他类型报错;native:自动增长,针对不同数据库意义不同-->
            <generator class="assigned" />
        </id>
        <property name="name" type="java.lang.String">
            <column name="NAME" />
        </property>
        <property name="gender" type="java.lang.String">
            <column name="GENDER" />
        </property>
        <property name="address" type="java.lang.String">
            <column name="ADDRESS" />
        </property>
    </class>
</hibernate-mapping>

 

hibernate.cfg.xml

标签:其他   lan   hbm   org   类型   ati   oct   赋值   actor   

原文地址:http://www.cnblogs.com/kundeg/p/7153452.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!