在spring和hibernate整合時: java
Caused by: java.lang.NoClassDefFoundError:
javax/persistence/EntityListeners
?at
org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.getDefaults(JPAMetadataProvider.java:96)
?at
org.hibernate.annotations.common.reflection.java.JavaReflectionManager.getDefaults(JavaReflectionManager.java:226)
?at
org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1355)Failed
to build a new SessionFactory from default source file.
java.lang.NoClassDefFoundError: javax/persistence/EntityListeners spring
?at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1826)
?at
exampleBeanTest.wwm.hibernate.util.HibernateUtil.buildNewSessionFactory(HibernateUtil.java:11)
?...
1 more
Caused by: java.lang.ClassNotFoundException:
javax.persistence.EntityListeners
?at java.net.URLClassLoader$1.run(Unknown
Source)
?at java.security.AccessController.doPrivileged(Native Method)
?at
java.net.URLClassLoader.findClass(Unknown Source)
?at
java.lang.ClassLoader.loadClass(Unknown Source)
?at
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
?at
java.lang.ClassLoader.loadClass(Unknown Source)
?... 6 more
Exception in
thread "main" api
解決方法:這個是hibernate3.6版本的;因此還缺乏JPA jar
包;還須要導入jar包。能夠在Hibernate 3.6
distro:
hibernate-distribution-3.6.0.Final/lib/jpa/hibernate-jpa-2.0-api-1.0.0.Final.jar找到以後導入就能夠了。爲何要加我也不知道,之前沒有注意過。 ide