整理hibernate.cfg.xml 与 applicationContext之间的配置方式
来源:互联网 发布:linux用户和组管理命令 编辑:程序博客网 时间:2024/05/19 00:47
注释掉为另一种
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- org.springframework.jdbc.datasource.DriverManagerDataSource org.apache.commons.dbcp.BasicDataSource -->
<!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/user"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
<property name="maxActive" value="100"></property>
<property name="maxIdle" value="30"></property>
<property name="maxWait" value="500"></property>
<property name="defaultAutoCommit" value="true"></property>
</bean> -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<!-- <property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>Bean/Message.xml</value>
<value>Bean/User.hbm.xml</value>
</list>
</property> -->
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/user</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123456</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">True</property>
<property name="format_sql">true</property>
<!-- 生成数据表的策略 -->
<property name="hbm2ddl.auto">update</property>
<!-- 设置 Hibernate 的事务隔离级别 -->
<property name="connection.isolation">2</property>
<!-- 删除对象后, 使其 OID 置为 null -->
<property name="use_identifier_rollback">true</property>
<!-- 设置缓存 -->
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/user</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123456</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">True</property>
<property name="format_sql">true</property>
<!-- 生成数据表的策略 -->
<property name="hbm2ddl.auto">update</property>
<!-- 设置 Hibernate 的事务隔离级别 -->
<property name="connection.isolation">2</property>
<!-- 删除对象后, 使其 OID 置为 null -->
<property name="use_identifier_rollback">true</property>
<!-- 设置缓存 -->
<property name="hibernate.cache.use_query_cache">true</property> <!-- 启动查询缓存 -->
<property name="hibernate.cache1.use_second_level_cache">true</property> <!-- 设置缓存机制为二级缓存 -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property> <!-- 设置二级缓存的Provider类 -->
<property name="hibernate.cache.provider_configuration_file_resource_path">/WEB-INF/classes/ehcache.xml</property> <!-- 设置缓存的配置文件路径 -->
<!-- 配置管理 Session 的方式 -->
<property name="current_session_context_class">thread</property>
<mapping resource="Bean/Message.xml" />
<mapping resource="Bean/User.hbm.xml" />
<class-cache class="Bean.Message" usage="read-only"
region="bean.message" />
<class-cache class="Bean.User" usage="read-only"
region="bean.user" />
<!-- 设置缓存 -->
<!-- 1.打开二级缓存 -->
<!-- <property name="hibernate.cache.use_second_level_cache">true</property> -->
<!-- 2、Hibernate的二级缓存使用第三方的缓存工具来实现,所以我们需要指定Hibernate使用哪个 缓存工具。如下配置指定Hibernate使用EhCache缓存工具。 -->
<!-- <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property> -->
<!-- 3、Hibernate在默认情况下并不会对所有实体对象进行缓存,所以,我们需要指定缓存哪些对象, 在实体对象的映射文件中(相应的<class>标签内部),添加如下配置:
注意,这个<cache>标签只能放在<class>标签的内部,而且必须处在<id>标签的前面!!! 这个<cache>标签放在哪些<class>标签下面,就说明会多这些类的对象进行缓存 -->
<!-- 4、对于第3步,有一个可选的方案是在hibernate.cfg.xml文件中指定哪些类的对象需要缓存, 而不需要使用<cache>标签来指定。如:
在hibernate.cfg.xml中添加如下配置: <class-cache class="Bean.Message" usage="read-only"
/> 注意,这个<class-cache>标签必须放在<mapping>标签的后面!! -->
</session-factory>
<property name="hibernate.cache1.use_second_level_cache">true</property> <!-- 设置缓存机制为二级缓存 -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property> <!-- 设置二级缓存的Provider类 -->
<property name="hibernate.cache.provider_configuration_file_resource_path">/WEB-INF/classes/ehcache.xml</property> <!-- 设置缓存的配置文件路径 -->
<!-- 配置管理 Session 的方式 -->
<property name="current_session_context_class">thread</property>
<mapping resource="Bean/Message.xml" />
<mapping resource="Bean/User.hbm.xml" />
<class-cache class="Bean.Message" usage="read-only"
region="bean.message" />
<class-cache class="Bean.User" usage="read-only"
region="bean.user" />
<!-- 设置缓存 -->
<!-- 1.打开二级缓存 -->
<!-- <property name="hibernate.cache.use_second_level_cache">true</property> -->
<!-- 2、Hibernate的二级缓存使用第三方的缓存工具来实现,所以我们需要指定Hibernate使用哪个 缓存工具。如下配置指定Hibernate使用EhCache缓存工具。 -->
<!-- <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property> -->
<!-- 3、Hibernate在默认情况下并不会对所有实体对象进行缓存,所以,我们需要指定缓存哪些对象, 在实体对象的映射文件中(相应的<class>标签内部),添加如下配置:
注意,这个<cache>标签只能放在<class>标签的内部,而且必须处在<id>标签的前面!!! 这个<cache>标签放在哪些<class>标签下面,就说明会多这些类的对象进行缓存 -->
<!-- 4、对于第3步,有一个可选的方案是在hibernate.cfg.xml文件中指定哪些类的对象需要缓存, 而不需要使用<cache>标签来指定。如:
在hibernate.cfg.xml中添加如下配置: <class-cache class="Bean.Message" usage="read-only"
/> 注意,这个<class-cache>标签必须放在<mapping>标签的后面!! -->
</session-factory>
</hibernate-configuration>
0 0
- 整理hibernate.cfg.xml 与 applicationContext之间的配置方式
- SSH整合配置applicationContext.xml/hibernate.cfg.xml/struts.xml
- Hibernate.cfg.xml的配置
- Hibernate.cfg.xml的配置
- hibernate.cfg.xml的配置
- hibernate.cfg.xml的配置
- Hibernate.cfg.xml的配置
- hibernate.cfg.xml的配置
- Hibernate.cfg.xml 整理
- Hibernate里面的hibernate.cfg.xml配置
- Hibernate的hibernate.cfg.xml配置
- 当spring和Hibernate集成时,在applicationContext.xml和Hibernate.cfg.xml配置sessionfactory区别
- Spring与Hibernate的整合applicationContext.xml中配置
- spring与hibernate集成--spring配置文件applicationContext.xml的配置:
- Spring与Hibernate整合的applicationContext.xml文件配置
- hibernate.cfg.xml配置
- hibernate.cfg.xml配置
- hibernate.cfg.xml配置
- spring
- mysql my.cnf文件配置
- pentaho bi server5.4MySQL部署
- 非常好的理解遗传算法的例子
- Cocos2d-x 3.X, IOS版添加广点通广告平台
- 整理hibernate.cfg.xml 与 applicationContext之间的配置方式
- windows命令行问题
- Oracle数据库备份、恢复 - 使用PL/SQL Developer 导入、导出Oracle数据库
- js echo中对像转成字符串
- SQL2008,SQL2005存储过程解密
- Spring MVC 参数依赖注入时,String参数注入为Date类型
- Registry Settings that can be Modified to Improve Operating System Performance
- app测试点
- 关于在链表中用递归形式,求出链表中的最大值,及节点数和平均值的函数