1.*.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 2018-3-23 17:41:34 by Hibernate Tools 3.5.0.Final -->
<hibernate-mapping>
<class name="com.dao.Entity" table="student">
<!--name是你的实体类路径、table是你的数据库表名 -->
<id name="id" column="Sno" type="string">
<!--name是与数据库表主键对应的属性,column是数据库表的主键 -->
<generator class="assigned" />
<!-- class="assigned"说明主键是自己定的,不是数据库生成的 -->
</id>
<property name="password" column="Cno" type="string">
</property>
</class>
</hibernate-mapping>
2. *.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">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=max</property>
<property name="connection.username">sa</property>
<property name="connection.password">123456</property>
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<!-- 连接数据库的方言,不同的数据库都会有自己对应的方言 -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping resource="com/dao/Entity.hbm.xml"/>
<!--resource= hbm.xml文件的路径 (注意是“\”,不是“.”)-->
</session-factory>
</hibernate-configuration>