------------------第一种配置方式--------------------------------
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:hibernate.cfg.xml"></property> </bean>把hibernate放在路径下
<session-factory>
<property name="hibernate.show_sql">true</property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property> <!-- 设置自动创建|更新|验证数据库表结构 --> <property name="hibernate.hbm2ddl.auto">update</property> <!-- 是否在控制台显示sql --> <property name="hibernate.show_sql">true</property> <!-- 是否格式化sql,优化显示 --> <property name="hibernate.format_sql">false</property> <!-- 是否开启二级缓存 --> <property name="hibernate.cache.use_second_level_cache">false</property> <!-- 是否开启查询缓存 --> <property name="hibernate.cache.use_query_cache">false</property> <!-- 数据库批量查询最大数 --> <property name="hibernate.jdbc.fetch_size">50</property> <!-- 数据库批量更新、添加、删除操作最大数 --> <property name="hibernate.jdbc.batch_size">50</property> <!-- 是否自动提交事务 --> <property name="hibernate.connection.autocommit">true</property> <!-- 指定hibernate在何时释放JDBC连接 --> <property name="hibernate.connection.release_mode">auto</property> <!-- 创建session方式 hibernate4.x 的方式 --> <property name="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</property> <!-- javax.persistence.validation.mode默认情况下是auto的,就是说如果不设置的话它是会自动去你的classpath下面找一个bean-validation**包 所以把它设置为none即可 --> <property name="javax.persistence.validation.mode">none</property><mapping resource="映射文件全路径" />
</session-factory>
</hibernate-configuration>----------------------------第二种配置方式------------------------------------------------
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" /> <!-- hibernate的相关属性配置 --> <property name="hibernateProperties"> <value> <!-- 设置数据库方言 --> hibernate.dialect=org.hibernate.dialect.Oracle10gDialect <!-- 设置自动创建|更新|验证数据库表结构 --> hibernate.hbm2ddl.auto=update <!-- 是否在控制台显示sql --> hibernate.show_sql=true <!-- 是否格式化sql,优化显示 --> hibernate.format_sql=false <!-- 是否开启二级缓存 --> hibernate.cache.use_second_level_cache=false <!-- 是否开启查询缓存 --> hibernate.cache.use_query_cache=false <!-- 数据库批量查询最大数 --> hibernate.jdbc.fetch_size=50 <!-- 数据库批量更新、添加、删除操作最大数 --> hibernate.jdbc.batch_size=50 <!-- 是否自动提交事务 --> hibernate.connection.autocommit=true <!-- 指定hibernate在何时释放JDBC连接 --> hibernate.connection.release_mode=auto <!-- 创建session方式 hibernate4.x 的方式 --> hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext <!-- javax.persistence.validation.mode默认情况下是auto的,就是说如果不设置的话它是会自动去你的classpath下面找一个bean-validation**包 所以把它设置为none即可 --> javax.persistence.validation.mode=none </value> </property> <property name="mappingDirectoryLocations"> <list> <value>classpath:映射文件的包名(当前包下所有的映射文件都会被扫描)</value> </list> </property> </bean>