所以我们有一个Spring文件,所以我们使用的是Hibernate-3.5.5
类= “org.springframework.orm.hibernate3.LocalSessionFactoryBean” >
<value>Run.hbm.xml
</value>
<prop key="hibernate.dialect">${dialect}</prop>
<prop key="hibernate.cache.provider_class">
<!-- org.hibernate.cache.ehcacheprovider-->
net.sf.ehcache.hibernate.EhCacheProvider
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">
true
</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.connection.autocommit">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.connection.release_mode">on_close</prop>
<prop key="hibernate.generate_statistics">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="org.hibernate.envers.audit_table_suffix">_Audit</prop>
<prop key="org.hibernate.envers.revision_field_name">REV</prop>
<prop key="org.hibernate.envers.revision_type_field_name">REVTYPE</prop>
<prop key="org.hibernate.envers.default_schema">SQN_OWN</prop>
<prop key="org.hibernate.envers.revision_on_collection_change">false</prop>
<entry key="post-insert">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="post-update">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="post-delete">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="pre-collection-update">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="pre-collection-remove">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
<entry key="post-collection-recreate">
<bean class="org.hibernate.envers.event.AuditEventListener" />
</entry>
当我启动应用程序时,我收到错误HibernateException无法初始化侦听器。进一步调试后,错误来自AuditConfiguration类:
AudiConfiguration(配置C){
属性properties = cfg.getProperties();
ReflectionManager reflectionManager =((AnnotationConfiguration)cfg).getReflectionManager();在classCastException上失败cfg不是AnnotationConfiguration的实例..
我可能做错了什么?
答案 0 :(得分:0)
这样做的原因是在AuditConfiguration的构造函数中,配置类型为强制转换为 AnnotationConfiguration。使用此Spring上下文片段,似乎解决了问题。
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="namingStrategy">
<ref bean="namingStrategy" />
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>