(一) Hibernate主配置文件,hibernate.cfg.xml
在该配置文件可以使用 <property name=""></property>
添加配置信息
常用属性介绍:
hibernate.connection.driver_class 连接数据库驱动程序
hibernate.connection.url 连接数据库URL
hibernate.connection.username 数据库用户名
hibernate.connection.password 数据库密码
hibernate.dialect 操作数据库方言
hibernate.show_sql true 在控制台上输出SQL语句
hibernate.format_sql true 格式化控制台输出的SQL语句
hibernate.hbm2ddl.auto create/create-drop/update/validate DDL策略
javax.persistence.validation.mode 持久类验证机制,一般不启用设置none
hibernate.connection.autocommit true 事务是否自动提交
<mapping resource="" />
用于添加映射文件
demo:
<?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工厂的配置(相当于连接池) -->
<session-factory>
<!-- 常规配置 -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- 可以处理中文乱码 -->
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=UTF-8</property>
<property name="hibernate