此项目曾经在 Java 8 和 NetBeans 8 中运行,但在将我的项目升级为使用 Java 19 和 NetBeans 16 后,我现在看到此错误:
Exception in thread "AWT-EventQueue-0" Local Exception Stack:
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: jdk.internal.loader.ClassLoaders$AppClassLoader@c387f44
Internal Exception: java.lang.NullPointerException: Cannot invoke "org.eclipse.persistence.internal.sessions.AbstractSession.getName()" because "this.session" is null
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:115)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:188)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at jdiskmark.EM.getEntityManager(EM.java:22)
at jdiskmark.DiskRun.findAll(DiskRun.java:146)
at jdiskmark.App.loadSavedRuns(App.java:219)
at jdiskmark.App.init(App.java:124)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.persistence.internal.sessions.AbstractSession.getName()" because "this.session" is null
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:2027)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:100)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:104)
这是投掷线:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("jDiskMarkPU");
em = emf.createEntityManager();
我的 persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="jDiskMarkPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.level" value="FINE"/>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:derbyDB;create=true"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
</properties>
</persistence-unit>
</persistence>
javax.persistence_2.1.1v201509150925.jar
项目源码在这里: https://gitlab.com/jamesmarkchan/jDiskMark
我换了 eclipselink.jar v4.0,由于 @Chris 的提示,这似乎解决了空指针问题。
目前看到
Exception in thread "AWT-EventQueue-0" javax.persistence.PersistenceException: No Persistence provider for EntityManager named jDiskMarkPU
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at jdiskmark.EM.getEntityManager(EM.java:22)
at jdiskmark.DiskRun.findAll(DiskRun.java:146)
at jdiskmark.App.loadSavedRuns(App.java:219)
at jdiskmark.App.init(App.java:124)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
我不确定是否需要更新 META-INF/persistence.xml 定义或者是否需要升级库。在 EclipseLink 4.0.1 download 中,我尝试链接一些库,但它没有解决我的 PU 问题。
我认为我需要更换以前的图书馆
这些是我尝试链接的库来代替它们。
但是 javax.persistence_2.1.1 似乎没有被 EclipseLink 包提供的库替换,所以我不确定应该使用哪个库来替换它,或者我主要只需要更新我的 persistence.xml 定义?
首先我必须感谢你,因为我从你的问题中得到了想法。就我而言,我也使用了 Guice。所以,我修改了Guice persist以采用jakarta并使用这两个依赖打击,然后我的问题就解决了:
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>jakarta.persistence</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>4.0.1</version>
</dependency>
当然我不需要,但我确实切换到了 jdk 21 w NetBeans 20 以利用当前的 LTS 版本。
需要为我的旧版 ant 版本更新的库:
类定义也已重新定位到 jakarta.persistence