## Hibernate 二级缓存配置中的问题##
hibernate配置完二级缓存之后会报错:
org.xml.sax.SAXParseException: The content of element type “session-factory” must match “(property*,mapping*,(class-cache|collection-cache),event,listener*)”.
Hibernate.cfg.xml文件的配置方法如下:
<!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 name="foo" >
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/lbxtest</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<!-- 是否使用二级缓存,默认为使用 -->
<property name="hibernate.cache.use_second_level_cache">true</property>
<!-- 缓存类型 -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.OSCacheProvider</property>
<!-- 指定需要缓存的类 ,还可以在配置文件*.hbm.xml中设置-->
<class-cache usage="read-write" class="cn.lbx.hibernate.domain.User"/>
<mapping resource="cn/lbx/hibernate/domain/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
从网上找到相关答案(http://bbs.csdn.net/topics/330186432),是因为User的缓存配置有问题,应该将下面两段代码交换位置就可以
<class-cache usage="read-write" class="cn.lbx.hibernate.domain.User"/>
<mapping resource="cn/lbx/hibernate/domain/User.hbm.xml"/>
</session-factory>