一些异常收集

时间:2023-02-11 22:48:27

1.Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext
导入spring-hibernation.jar bao

2.Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)
删除asm_2.3.jar


3.类名 is not mapped. (某个类没有映射)-------------->hql语句关于表名大小写错误


4.failed to lazily initialize a collection of role: com.stuclazz.entity.Clazz.students - no session or session was closed
即延迟加载错误,解决方法一:设置lazy=false
解决方法二:在web.xml中配置过滤器,代码如下
<filter>
<filter-name>myOpenSessionFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>myOpenSessionFilter</filter-name>
r remove 'readOnly' marker from transaction definition


5. Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition
解决方法为:在添加时写上this.getHibernateTemplate().setFlushMode(2);

6.No bean specified ,解决方法为:在一对多的关系中,关于多的一方的实体类中对应的一的一方,未实例化。此时,只需实例化即可。


7.Unable to load configuration. - bean - jar:file:/C:/Tomcat%206.0/webapps/S2SH/WEB-INF/lib/struts2-core-2.1.6.jar!/struts-default.xml:68:140
在struts.xml中,引用的配置文件有误!应该是2.1版本的.例如:

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>


8.Error creating bean with name 'sessionFactory' defined in class path resource [spring.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext

解决方法:导入hibernate3.jar 覆盖之前的就可以了!


9. parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist

解决方法:applicationContext.xml配置文件存在的位置找不到,将其移到src目录下即可,默认的classPath目录下,即在src目录下

10.No action instance for path /book could be created

(好久没整合ssh框架了,在整合s1sh框架时所遇到的问题,出现的原因是:在struts-config.xml文件中没有配置controller元素,即没有通知struts将拦截的请求交给spring context下的bean,所以在bean中配置的请求路径不能被创建!做如下配置即可:)
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor">
</controller>


11.java.lang.IllegalArgumentException: No bean specified

(没有bean被指定,在s1sh整合中,在form中构造实体的实例即可,即必须使用new实例)


12.Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: entity class not found: com.scce.TbBookInfo
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1336)
解决方法:重新使用hibernate reverse 生成一遍实体类,选对路径!

13.org.springframework.dao.InvalidDataAccessResourceUsageException: could not update: [com.scce.entity.TbBookInfo#9]; nested exception is org.hibernate.exception.DataException: could not update: [com.scce.entity.TbBookInfo#9]
现象描述:控制台将update语句打出,没问题。
解决方法:数据库中的字段容量设计的太小了。。。 亦或是,将插入数据的字段长度改小即可。