1,nested exception is java.lang.NoClassDefFoundError:org/hibernate/engine/SessionFactoryImplementor
hibernate4整合spring3 时出现 nested exception is java.lang.NoClassDefFoundError:org/hibernate/engine/SessionFactoryImplementor
异常
原因:3中这样配置
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
<property name="nestedTransactionAllowed" value="true" />
</bean>
原因:4中该这样配置
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="dataSource" ref="dataSource" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
5跟4一样设置
2, 解决Hibernate Write operations are not allowed in read-only mode的方法
错误信息:
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
解决方法:
在出现异常的方法中加入
getHibernateTemplate().setFlushMode(HibernateTemplate.FLUSH_EAGER);
//hibernate3
getHibernateTemplate().setCheckWriteOperations(false);
//hibernate5
3,java.lang.ClassNotFoundException: org.aopalliance.intercept.MethodInterceptor
出现了Java.lang.NoClassDefFoundError:的错误,首先想到的就是少包,在网上搜搜了,果然是少了一个叫aopalliance.jar的jar包,下载这个包,加到路径里就OK了。
4,The prefix “tx” for element “tx:advice” is not bound 错误的说明
这个错误的原因是:我们在定义申明AOP的时候,没有加载schema。
Spring的配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
添加之后Eclipse就能够识别<tx:advice/>,<aop:config/>
标签了。
5,Cannot locate the chosen ObjectFactory implementation
解决办法是:添加struts2-spring-plugin-*.jar 包
6,java.lang.NoClassDefFoundError:
org/hibernate/engine/SessionFactoryImplementor
解决方法:来至于http://www.cnblogs.com/Mr-Clint/p/3580287.html
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager" >
<property name="dataSource" ref="dataSource" /> <!-- 添加这一行 --!>
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>