1.hibernate5的基础jar包
https://pan.baidu.com/s/10qolMgIPJw7HX_e6SEVk6g
2.hibernate.properties
<!-- DB链接四要素 -->
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://127.0.0.1:3306/Hib
hibernate.connection.username=root
hibernate.connection.password=qianqian1996
3.bean对象的配置文件
2.1 命名方式 beanName.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.home.beans">
<!--
映射文件的作用:
1)类到表的映射
2)属性到字段的映射
-->
<class name="Student" table="t_Student">
<id name="id" column="tid">
<generator class="native"/>
</id>
<property name="name" column="tname"></property>
<property name="age" column="tage"></property>
<property name="score" column="tscore"></property>
</class>
</hibernate-mapping>
4.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.MySQL5Dialect
</property>
<!-- 注册数据源C3P0、数据库连接池 -->
<property name="hibernate.connection.provider_class">
org.hibernate.c3p0.internal.C3P0ConnectionProvider
</property>
<!-- 注册当前session上下文,保证同一个线程中获取到是同一个session -->
<property name="hibernate.current_session_context_class">
thread
</property>
<!-- 自动建表 -->
<property name="hibernate.hbm2ddl.auto">
update
</property>
<!-- 显示SQL -->
<property name="hibernate.show_sql">
true
</property>
<!-- 格式化SQL -->
<property name="hibernate.format_sql">
true
</property>
<!-- 注册映射文件 -->
<mapping resource="com/home/beans/Student.hbm.xml" />
</session-factory>
</hibernate-configuration>