我正在尝试使用eclipselink学习jpa。我使用mysql作为我的数据库。我已经添加了所有需要的依赖项,下面是我的pom.xml
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.7.0</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
<scope>runtime</scope>
</dependency>
</dependencies>
问题是,即使maven已经下载了mysql jdbc连接器所需的所有jar,我还是得到了异常描述:configuration error。找不到类[com.mysql.cj.jdbc.driver]。以下是我正在使用的版本:1。mysql jdbc连接器:8.0.11.2。Eclipse:2.7.13。jpa:2.2.0版本
附件是我的maven依赖jars的截图。
我尝试了stackoverflow上其他线程的所有建议,但无法解决问题。
感谢您的帮助和提前感谢!
下面是我的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="Eclipselink_JPA" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jpadb"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
<property name="eclipselink.logging.level" value="FINE"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
另外,添加错误堆栈跟踪:
[el fine]:服务器:2018-06-24 17:33:10.619——线程(thread[main,5,main])——配置的服务器平台:org.eclipse.persistence.platform.server.noserverplatform[el info]:2018-06-24 17:33:11.065——服务器会话(1101598632)——线程(thread[main,5,main])——eclipseelink,版本:eclipse persistence services-2.6.5.v20170607-b3d05bd[el severe]:ejb:2018-06-24 17:33:11.068--serversession(1101598632)--线程(thread[main,5,main])--异常[eclipseelink-4003](eclipse persistence services-2.6.5.v20170607-b3d05bd):org.eclipse.persistence.exceptions.databaseexception异常描述:配置错误。找不到类[com.mysql.cj.jdbc.driver]。线程“main”javax.persistence.persistenceexception中的异常:异常[eclipseelink-4003](eclipse persistence services-2.6.5.v20170607-b3d05bd):org.eclipse.persistence.exceptions.databaseexception异常描述:配置错误。找不到类[com.mysql.cj.jdbc.driver]。位于org.eclipse.persistence.internal.jpa.entitymanagersetupimpl.deploy(entitymanagersetupimpl。java:818)位于org.eclipse.persistence.internal.jpa.entitymanagerfactorydelegate.getabstractsession(entitymanagerfactorydelegate)。java:207)在org.eclipse.persistence.internal.jpa.entitymanagerfactorydelegate.createentitymanagerimpl(entitymanagerfactorydelegate)。java:307)位于org.eclipse.persistence.internal.jpa.entitymanagerfactoryimpl.createentitymanagerimpl(entitymanagerfactoryimpl)。java:337)在org.eclipse.persistence.internal.jpa.entitymanagerfactoryimpl.createentitymanager(entitymanagerfactoryimpl。java:303)在practice.jpa.persistence.app.main(app。java:17)引起原因:异常[eclipselink-4003](eclipse persistence services-2.6.5.v20170607-b3d05bd):org.eclipse.persistence.exceptions.databaseexception异常描述:配置错误。找不到类[com.mysql.cj.jdbc.driver]。在org.eclipse.persistence.exceptions.databaseexception.configurationerrorclassnotfound(databaseexception。java:89)位于org.eclipse.persistence.sessions.defaultconnector.loaddriverclass(defaultconnector。java:267)在org.eclipse.persistence.sessions.defaultconnector.connect(defaultconnector。java:85)在org.eclipse.persistence.sessions.datasourcelogin.connecttodatasource(datasourcelogin。java:162)在org.eclipse.persistence.internal.sessions.databasesessionimpl.setordetectdatasource(databasesessionimpl。java:214)在org.eclipse.persistence.internal.sessions.databasesessionimpl.login和detectdatasource(databasesessionimpl。java:776)在org.eclipse.persistence.internal.jpa.entitymanagerfactoryprovider.login(entitymanagerfactoryprovider)。java:265)位于org.eclipse.persistence.internal.jpa.entitymanagersetupimpl.deploy(entitymanagersetupimpl。java:734) ... 5个以上
1条答案
按热度按时间vcirk6k61#
我的项目使用mysql和jpa的eclipselink实现,运行良好。我的pom文件: