1、 Invalid property 'orderDAO' of bean class [com.tarena.action.OrderDeleteAction]: Bean property 'orderDAO' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
解释:这是可能是因为applicationContext.xml中OrderDeleteAction对应的bean中为OrderDAO设置了属性,而OrderDeletAction中已经没有这个属性了。
2、No value for key [org.hibernate.impl.SessionFactoryImpl@1b912ed] bound to thread
解释:这是很可能是因为一个service中涉及到两个dao操作,但是前一个dao操作完以后关闭了session,第二个dao再操作的时候,session已经关闭了,所以会出现这种异常。
在上一篇日志中,我们曾经讲过,使用spring整合hibernate和struts以后,根据id来删除某一条记录主要有两种方式。对于第一种方式,特别容易出现以上错误。假如将session绑定在dao级别,每一个dao操作都会进行一次session的开与关,这是那两种删除方式可能都不会有太大的问题,但是,一旦将session绑定在service级别时,方式一就很容易出问题了,而方式二可以通过在web.xml中加上以下一段配置来解决:
<filter>
<filter-name>opensessioninview</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>opensessioninview</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3、以下是对什么是“session绑定到dao级别,和什么是session绑定到service级别”做一些个人的解释:
1)session绑定到dao级别。action直接调用的dao
2)session绑定到service级别。action直接调用的是service