N条Struts和Hibernate的经验
1. 定义Action后, 如果指定了name, 那么必须要定义一个与它同名的FormBean才能进行form映射.
2. 如果定义Action后, 提交页面时出现 "No input attribute for mapping path..." 错误, 则需要在其input属性中定义转向的页面.
3. 如果插入新的数据时出现 " Batch update row count wrong:..." 错误, 则说明XXX.hbm.xml中指定的key的类型为原始类型 (int, long), 因为这种类型会自动分配值, 而这个值往往会让系统认为已经存在该记录, 正确的方法是使用 java.lang.Integer或java.lang.Long对象.
原因:
新版本的MySQL对字段的严格检查。
解决方法:
修改my.ini,将
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
改为
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"。
重新启动MySQL。
4. 如果插入数据时出现 "argument type mismatch" 错误, 可能是你使用了Date等特殊对象, 因为struts不能自动从String型转换成Date型, 所以, 你需要在Action中手动把String型转换成Date型.
5. Hibernate中, Query的iterator()比list()方法快很多.
6. 如果出现 "equal symbol expected" 错误, 说明你的strtus标签中包含另一个标签或者变量, 例如:
<html:select property="test" onchange="<%=test%>"/>
或者
<html:hidden property="test" value="<bean:write name="t" property="p"/>"/>
这样的情况...