无法构建未找到的EntityManagerFactory + JDBC驱动程序类

时间:2013-10-10 20:56:16

标签: java mysql hibernate maven gwt

我有这个项目,我正在使用hibernate,maven,gwt,JPA,Tomcat和spring,mysql。无论如何,我一直试图解决这个错误没有成功。 我已经配置了我的mysql连接器“mysql-connector-java” 这是我的错误:

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

1 个答案:

答案 0 :(得分:1)

我记得你在使用maven。如果pom.xml中有以下条目,请确保清理并构建项目并重新启动服务器以获取对类路径的更改

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

这个家伙有一些很好的教程btw

这是一个如何使用hibernate,maven和mysql

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