#java #jpa #eclipselink #h2
Вопрос:
Я пытаюсь запустить приложение javafx, которое использует eclipselink и локальную базу данных H2, но я получаю следующую ошибку:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.salesinvoicetools.salesinvoicetools/com.salesinvoicetools.AppWindow.subMain(AppWindow.java:62)
at com.salesinvoicetools.salesinvoicetools/com.salesinvoicetools.Starter.main(Starter.java:13)
Caused by: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: jdk.internal.loader.ClassLoaders$AppClassLoader@233c0b17
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [h2-localdb] failed.
Internal Exception: java.lang.IncompatibleClassChangeError: class org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAsmFactory$ClassMetadataVisitor can not implement org.eclipse.persistence.internal.libraries.asm.ClassVisitor, because it is not an interface (org.eclipse.persistence.internal.l
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:129)
at org.eclipse.persistence.jpa@2.5.0/org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:107)
at org.eclipse.persistence.jpa@2.5.0/org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
at javax.persistence@2.1.0/javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence@2.1.0/javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.salesinvoicetools.salesinvoicetools/com.salesinvoicetools.dataaccess.DataAccessBase.setEntityManager(DataAccessBase.java:23)
at com.salesinvoicetools.salesinvoicetools/com.salesinvoicetools.dataaccess.DataAccessBase.<clinit>(DataAccessBase.java:19)
... 2 more
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [h2-localdb] failed.
Internal Exception: java.lang.IncompatibleClassChangeError: class org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAsmFactory$ClassMetadataVisitor can not implement org.eclipse.persistence.internal.libraries.asm.ClassVisitor, because it is not an interface (org.eclipse.persistence.internal.l
at org.eclipse.persistence.jpa@2.5.0/org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:1950)
at org.eclipse.persistence.jpa@2.5.0/org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1941)
at org.eclipse.persistence.jpa@2.5.0/org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:98)
at org.eclipse.persistence.jpa@2.5.0/org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:96)
... 7 more
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.7.8.v20201217-ecdf3c32c4): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [h2-localdb] failed.
Internal Exception: java.lang.IncompatibleClassChangeError: class org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAsmFactory$ClassMetadataVisitor can not implement org.eclipse.persistence.internal.libraries.asm.ClassVisitor, because it is not an interface (org.eclipse.persistence.internal.l
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:233)
... 11 more
Caused by: java.lang.IncompatibleClassChangeError: class org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAsmFactory$ClassMetadataVisitor can not implement org.eclipse.persistence.internal.libraries.asm.ClassVisitor, because it is not an interface (org.eclipse.persistence.internal.l
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1088)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:182)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:814)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:735)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:660)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
at org.eclipse.persistence.jpa@2.5.0/org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processEntityMappings(MetadataProcessor.java:538)
at org.eclipse.persistence.jpa@2.5.0/org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:581)
at org.eclipse.persistence.jpa@2.5.0/org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1865)
... 9 more
Я скопировал код сохранения из более старого проекта eclipse, который также использует h2 и eclipselink, но теперь он не запускается.
Я попытался добавить несколько операторов requires в module-info.java но все равно никаких изменений.
Вот записи в pom.xml файл:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.7.8</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
</dependency>
Есть какие-нибудь идеи?
Ответ №1:
Возможно, у вас есть две версии eclipselink в ваших зависимостях.
Старая версия 2.5.0 имеет интерфейс ClassVisitor
package org.eclipse.persistence.internal.libraries.asm;
/**
* A visitor to visit a Java class. The methods of this interface must be called
* in the following order: <tt>visit</tt> [ <tt>visitSource</tt> ] [
* <tt>visitOuterClass</tt> ] ( <tt>visitAnnotation</tt> |
* <tt>visitAttribute</tt> )* (<tt>visitInnerClass</tt> |
* <tt>visitField</tt> | <tt>visitMethod</tt> )* <tt>visitEnd</tt>.
*
* @author Eric Bruneton
*/
public interface ClassVisitor {...
в новой версии 2.7.8 появился абстрактный класс ClassVisitor:
package org.eclipse.persistence.internal.libraries.asm;
/**
* A visitor to visit a Java class. The methods of this class must be called in the following order:
* {@code visit} [ {@code visitSource} ] [ {@code visitModule} ][ {@code visitNestHost} ][ {@code
* visitPermittedSubclass} ][ {@code visitOuterClass} ] ( {@code visitAnnotation} | {@code
* visitTypeAnnotation} | {@code visitAttribute} )* ( {@code visitNestMember} | {@code
* visitInnerClass} | {@code visitRecordComponent} | {@code visitField} | {@code visitMethod} )*
* {@code visitEnd}.
*
* @author Eric Bruneton
*/
public abstract class ClassVisitor {
Вам необходимо удалить одну из двух зависимостей