1.Tomcat和项目的lib目录下均要加入mysql数据库驱动mysql-connector-java-5.0.8-bin.jar。在bean中配置数据源的时候,请注意严格按照下面方式配置:
<bean ></property>
</bean>
上面的黑色部分我曾经出错了,导致Cannot Load JDBC 异常。
2. Struts action 配置与Spring配置时候出现的问题:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="doctors" extends="struts-default">
<action name ="savePatient" class="savePatientAction">
<result name="redirect">ListPatient.action</result>
<result name="input">/AddPatients.jsp</result>
</action>
</package>
</struts>
name的名称与显示层的JSP的Form表单提交名称一致,class的名称必须与在Spring中配置的bean的id号一致:
<bean />
</property>
</bean>
3.
form 标签 没有namespace属性
解决方法:将“一对多”关系中的“一”方,not-null设置为false
(参考资料:http://www.thearcmind.com/confluence/pages/viewpage.action?pageId=212)
异常2:org.hibernate.TransientObjectException: object references an unsaved transient instance
解决方法:cascade="save-update,persist"
(参考资料:http://www.laliluna.de/254.html)
异常3:org.hibernate.QueryException: could not resolve property
解决方法:"from Category category where category.userID = :userID"修改为"from Category category where userID = :userID"或者"from Category category where category.user.id = :userID"
(参考资料:http://www.laliluna.de/277.html)
异常4:could not initialize proxy - the owning Session was closed
解决方法:设置lazy为false
(参考资料:http://forum.springframework.org/showthread.php?t=27993)
</property>
</bean>