java.lang.NoClassDefFoundError: org/hibernate/exception/DataException at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:615) at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:377) at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:974) at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:967) at com.lesoa.common.dao.impl.CommonDaoHibernateImpl.queryByProperty(CommonDaoHibernateImpl.java:333) at com.lesoa.common.dao.impl.CommonDaoHibernateImpl.queryOneByProperty(CommonDaoHibernateImpl.java:315) at com.lesoa.sysM.service.impl.UserServiceImpl.queryOneByUserName(UserServiceImpl.java:64) ......
出现该问题的原因是没有找到相关的class文件。
仔细检查项目中Hibernate包中的class文件,发现的确没有DateException.class这个文件。重新下载一个Hibernate包导入。问题解决。
又出现下面问题:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonDaoHibernate' defined in class path resource [test/applicationContext.xml]: Cannot resolve reference to bean 'oaSessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oaSessionFactory' defined in class path resource [test/applicationContext-datasource.xml]: Invocation of init method failed; nested exception is java.lang.UnsupportedClassVersionError: org/hibernate/cfg/SecondPass (Unsupported major.minor version 49.0) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oaSessionFactory' defined in class path resource [test/applicationContext-datasource.xml]: Invocation of init method failed; nested exception is java.lang.UnsupportedClassVersionError: org/hibernate/cfg/SecondPass (Unsupported major.minor version 49.0) Caused by: java.lang.UnsupportedClassVersionError: org/hibernate/cfg/SecondPass (Unsupported major.minor version 49.0) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:147) at java.net.URLClassLoader.defineClass(URLClassLoader.java:474) at java.net.URLClassLoader.access$500(URLClassLoader.java:108) at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:846) ......
在Google中搜索发现导致该问题的原因有两个,下面是引用别人的描述:
1,It's relatively easy - hibernate.jar that you use was compiled with JDK 1.5 (corresponds to class file version 49) without specifiying a target option.
You need to rebuild that jar from source using JDK 1.4. Just download hibernate sources, unpack and run build.bat. Note that Hibernate's build.xml has target specifed as 1.4, so you have to obtain jar usable with 1.4 even if you compile with 1.5. (因为导入的包class文件的编译JDK同项目的JDK不相符导致,需要对导入包重新编译)
2,Another cause of problem may be that you have somewhere on classpath another version of the hibernate.jar (or class in question outside of jar).(因为在导入的包里面有其他的相同的class文件并且版本不一样,需要移除一个。)
对我导入的Hibernate包进行查找发现Hibernate3.jar和Hibernate-annotation里面有相同的文件,移除Hibernate-annotation包,问题解决。但又出现下面问题:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonDaoHibernate' defined in class path resource [test/applicationContext.xml]: Cannot resolve reference to bean 'oaSessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oaSessionFactory' defined in class path resource [test/applicationContext-datasource.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javassist/util/proxy/MethodFilter Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oaSessionFactory' defined in class path resource [test/applicationContext-datasource.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javassist/util/proxy/MethodFilter Caused by: java.lang.NoClassDefFoundError: javassist/util/proxy/MethodFilter at org.hibernate.bytecode.javassist.BytecodeProviderImpl.getProxyFactoryFactory(BytecodeProviderImpl.java:49) at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactoryInternal(PojoEntityTuplizer.java:203) at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:181) at org.hibernate.tuple.entity.AbstractEntityTuplizer.(AbstractEntityTuplizer.java:158) at org.hibernate.tuple.entity.PojoEntityTuplizer. (PojoEntityTuplizer.java:76) ......
该问题是因为没有导入javassist.jar包,导入即可。上述问题解决之后,程序能够找到异常类并给予相关错误的准确提示:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: userName of: com.lesoa.sysM.vo.T_USER; nested exception is org.hibernate.QueryException: could not resolve property: userName of: com.lesoa.sysM.vo.T_USER Caused by: org.hibernate.QueryException: could not resolve property: userName of: com.lesoa.sysM.vo.T_USER at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:67) at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:61) at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1402) at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:54) at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1377) at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:457)
在t_user类里面没有找到对应的userName属性!(这里是我们的命名规范很又问题,实在是丢人)!以后切记!将userName改为username问题解决。
所以项目中错误的包的引入是一件很让人头疼的事情!