Q1. 2010-12-28 查询数据时遇到异常: org.hibernate.LazyInitializationException -failed to lazily initialize a collection of role.
解决 :在 web.xml 中添加过滤器:
<!-- Hibernate Open Session In View filter--> <filter> <filter-name>hibernateOpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>hibernateOpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
Q2. 2011-1-5 查询数据时遇到异常: java.lang.NoClassDefFoundError: Anltr/ANTLRException.
解决 : 加上 antlr-2.7.6.jar (jar具体版本需与当前环境匹配,我的环境: Spring 3.0.1 + Hibernate 3.3.2GA)
Q3. 2011-1-6 一个简单的表单提交功能,在Ubuntu下的Firefox和Chrome提交表单之后,没有如期待中的执行action,而在Windows下却是ok的。 (关键类库版本:xwork-core-2.1.6)
原因 : 凡事总有原因,将 com.opensymphony.xwork2 日志级别改为 INFO, 再提交,果然问题原因浮现:
Caused by: java.lang.NoSuchMethodException: ....TabRole.setStartExpire([Ljava.lang.String;)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1206)
... 110 more
jsp上该表单元素是这么写的:<input type="text" name="entity.startExpire" value="${entity.startExpire}"/>
entity 是 TabRole 类型的,TabRole 是持久层的数据模型对象,其中 startExpire 是 Date 类型的,大致原因就是这个了。
至于为何在不同的OS下有此差别,尚有待研究。
see:http://ruinxdgzy.iteye.com/blog/805138
Q4. 2011-7-11 发现SpringSide v3.3.3 中类 PropertyFilter 的1个bug:
使用 new PropertyFilter("EQI_usbRevision", "value"); 构造查询条件,预期结果字段名应当是 usbRevision,而实际结果却变成了[usb, evision]。
原因 :经过调试,发现问题出在类 PropertyFilter 第79行:
propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR);
此行执行后 propertyNames 值变成了一个数组, 一开始以为是 split 方法的bug,后仔细看 split 方法说明,发现是 PropertyFilter 没有弄清楚这个split 方法的用法,split 方法并不是把 String separatorChars 这个参数的值作为整体来进行分割,而是匹配其中的单个字符的,usbRevision 这个名称中有R,故被分割了。正确的应调用 StringUtils.splitByWholeSeparator 方法进行分割。
解决 :在不修改类库源码的情况下,调整字段名,避免出现 O 和 R,则可避免字段名被错误解析。
(注:随后去SpringSide官网寻觅新版本,查看v3.3.4src,发现该bug已被修复。)
Q5. 2011-7-16 Ubuntu11.04 64bit下部署1个webapp到Tomcat,结果报连不上DB(Oracle10g、c3p0):
ERROR [org.hibernate.util.JDBCExceptionReporter] - Connections could not be acquired from the underlying database!
当时,本人电脑双系统(windows7、ubuntu10.04LTS)下分别试验,发现win7下ok,ubuntu下也有同样问题,而用数据库客户端连接则均是ok的。
原因 :网上搜索发现遇到此问题的极多,但没有明确的解决方案,要不就是没解决,要不就是莫名奇妙的就解决了。
解决 :在连不上的那台电脑上试了n多种方法(copy连接池相关jar包到tomcat的libs下==)均无效,后来换了台电脑部署(OS环境相同、JDK等配置均采用原始配置、未做过多改动),居然就OK了。
(这个问题有时间一定要好好研究下到底是何原因。)
Q6. 2011-12-15 Hibernate(版本3) HQL更新数据,时间类型字段值用以下方法设置时,时分秒变成了00:00:00:
Query query = session.createQuery ("..."); query.setDate("...", new Date());
解决 :改为使用 query. setTimestamp("...", new Date()); 方法。
Q7. 2012-3-13 2个应用实例同时对同个数据库(MySQL)、同张数据表存在读写操作,写入时遇到主键冲突。
原因 :hibernate 映射数据表主键字段使用了 increment 。
解决 :改为使用 identity。
see:hibernate的主键生成方式
Q8. 2012-6 配置了1个AOP拦截方法,应用启动时报错: error at ::0 formal unbound in pointcut
原因 :拦截方法的参数有问题。
解决 :删除该方法的所有参数,或将方法参数改为 JoinPoint 类型或其他 JoinPoint 相关类型。
see: http://blog.csdn.net/llbupt/article/details/6611901