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>
			<!-- 1 基本四项 -->
			<!-- 连接数据库的驱动 -->
			<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
			<!-- 连接数据库的URL -->
			<property name="hibernate.connection.url">jdbc:mysql:///hibernate_0</property>
			<!-- 连接数据库的用户名 -->
			<property name="hibernate.connection.username">root</property>
			<!-- 连接数据库的密码 -->
			<property name="hibernate.connection.password">1234</property>
			
			<!-- 2 与本地线程绑定 -->
			<property name="hibernate.current_session_context_class">thread</property>
			
			<!-- 3 方言:为不同的数据库,不同的版本,生成sql语句 -->
			<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dilect</property>
			
			<!-- 4 sql语句 -->
			<!-- 显示sql语句 -->
			<property name="hibernate.show_sql">true</property>
			<property name="hibernate.format_sql">true</property>
			
			<!-- 5 自动创建表(了解),学习中可以用,实际开发中用不到 ,实际开发中是先建表,再根据表产生PO类
			 取值:
			(1)update:如果表不存在,将创建表;如果表已经存在,通过hbm映射文件更新表
			(2)create:如果表存在,先删除,再创建。程序结束时,之前创建的表不删除
			(3)create-drop:与create几乎一样。如果factory.close()执行,将在JVM关闭的同时,将创建的表删除了
			(4)validate:校验hbm映射文件和表的列是否对应,如果对应正常执行,如果不对应则抛出异常
			-->
			<property name="hibernate.hbm2ddl.auto">create</property>
			
			<!-- 6 java web 6.0存在一个问题 
			*BeanFactory空指针异常   异常提示:org.hibernate.HibernateException:Unable to get the default Bean Validation factory
			*解决方案:取消bean校验
			-->
			<property name="javax.persistence.validation.mode">none</property>
			
			<!-- 加载映射文件 -->
			<mapping resource="com/zju/model/User.hbm.xml"/>
		</session-factory>
	</hibernate-configuration>

猜你喜欢

转载自blog.csdn.net/pcwl1206/article/details/80624956