2013-10-10 115 views
1

我有這個項目,我使用休眠,maven,gwt,JPA,Tomcat和spring,mysql。無論如何,我一直試圖解決這個錯誤沒有成功。 我已經配置我的MySQL連接器 「使用mysql-connector-java的」 這是我的錯誤:無法構建EntityManagerFactory + JDBC驅動程序類未找到

Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: projetA] Unable to build EntityManagerFactory 
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:892) 
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56) 
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48) 
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32) 
    at com.pac.projetA.shared.Dto.Main.main(Main.java:14) 
Caused by: org.hibernate.HibernateException: JDBC Driver class not found: org.mysql.jdbc.Driver 
    at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:89) 
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137) 
    at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:51) 
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:91) 
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163) 
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2159) 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1383) 
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954) 
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:883) 
    ... 4 more 
Caused by: java.lang.ClassNotFoundException: org.mysql.jdbc.Driver 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252) 
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Class.java:169) 
    at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192) 
    at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:84) 
    ... 12 more 
    enter code here 
+0

你是如何配置罐子? –

+0

我在類路徑中添加了jar我+我在pom.xml中添加了依賴關係 – mitchi

+0

我建議你不要同時執行這兩個操作。 –

回答

1

我記得你使用maven。確保清理並生成項目,並重新啓動服務器以獲取更改到classpath如果你有在你的pom.xml以下條目

<dependency> 
    <groupId>mysql</groupId> 
    <artifactId>mysql-connector-java</artifactId> 
    <version>5.1.6</version> 
</dependency> 

這傢伙有一些很好的教程,順便說一句

這是一個如何使用休眠,maven和mysql

http://www.mkyong.com/spring/maven-spring-hibernate-annotation-mysql-example/

相關問題