hibernate.cfg.xml主要在此文件中配置数据库连接的所需要的参数,和pojo的映射文件的路径。
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory>
<!-- 配置数据库驱动 -->
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<!-- 配置数据库URL -->
<property name="hibernate.connection.url">jdbc:oracle:thin:@172.16.11.98:1521:orcl</property>
<!-- 配置数据库用户名 -->
<property name="hibernate.connection.username">teacher</property>
<!-- 配置数据库密码 -->
<property name="hibernate.connection.password">teacher</property>
<!-- 配置数据库方言 -->
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<!-- 是否显示sql语句 -->
<property name="hibernate.show_sql">true</property>
<!-- 是否格式化sql语句 -->
<property name="hibernate.format_sql">true</property>
<!-- Hibernate中缓存的统计策略 http://blog.163.com/qqabc20082006@126/blog/static/2292852520091120112719561/-->
<property name="hibernate.generate_statistics">true</property>
<!-- 默认情况下是auto的,就是说如果不设置的话它是会自动去你的classpath下面找一个bean-validation**包,但是找不到,所以beanvalitionFactory错误 -->
<property name="javax.persistence.validation.mode">none</property>
<!-- 使用hibernate的注解功能 -->
<property name="configurationClass">org.hibernate.cfg.AnnotationConfiguration</property>
<!-- 一对一 多对多 一对多 加载的时候抓取的深度 -->
<property name="hibernate.max_fetch_depth">3</property>
<mapping resource="com/iflysse/hiber/domain/ForumGroup.hbm.xml"/>
<mapping resource="com/iflysse/hiber/domain/ForumUsers.hbm.xml"/>
<mapping resource="com/iflysse/hiber/domain/ForumUserAcc.hbm.xml"/>
<mapping resource="com/iflysse/hiber/domain/ForumRoles.hbm.xml"/>
</session-factory>
</hibernate-configuration>