Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to create entity manager when running an app using module path #1507

Closed
grigoriliev opened this issue May 6, 2022 · 1 comment · Fixed by #1528
Closed

Failing to create entity manager when running an app using module path #1507

grigoriliev opened this issue May 6, 2022 · 1 comment · Fixed by #1528

Comments

@grigoriliev
Copy link

I'm getting the following exception when trying to create an entity manager when running an app using module path, instead of using classpath:

Exception in thread "main" jakarta.persistence.PersistenceException: java.lang.NullPointerException
	at org.eclipse.persistence.jpa@4.0.0-M3/org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:861)
	at org.eclipse.persistence.jpa@4.0.0-M3/org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:221)
	at org.eclipse.persistence.jpa@4.0.0-M3/org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:328)
	at org.eclipse.persistence.jpa@4.0.0-M3/org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:343)
	at org.eclipse.persistence.jpa@4.0.0-M3/org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:306)
	at com.example.modpathtest@1.0.0-SNAPSHOT/com.example.modpathtest.Main.main(Main.java:10)
Caused by: java.lang.NullPointerException
	at java.base/java.io.Reader.<init>(Reader.java:168)
	at java.base/java.io.InputStreamReader.<init>(InputStreamReader.java:76)
	at org.eclipse.persistence.core@4.0.0-M3/org.eclipse.persistence.internal.helper.DBPlatformHelper.load(DBPlatformHelper.java:163)
	at org.eclipse.persistence.core@4.0.0-M3/org.eclipse.persistence.internal.helper.DBPlatformHelper.loadFromResource(DBPlatformHelper.java:145)
	at org.eclipse.persistence.core@4.0.0-M3/org.eclipse.persistence.internal.helper.DBPlatformHelper.initializeNameToVendorPlatform(DBPlatformHelper.java:90)
	at org.eclipse.persistence.core@4.0.0-M3/org.eclipse.persistence.internal.helper.DBPlatformHelper.getDBPlatform(DBPlatformHelper.java:61)
	at org.eclipse.persistence.core@4.0.0-M3/org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:265)
	at org.eclipse.persistence.core@4.0.0-M3/org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:808)
	at org.eclipse.persistence.jpa@4.0.0-M3/org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:259)
	at org.eclipse.persistence.jpa@4.0.0-M3/org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:772)

Here is a test app, which can be run with 'mvn exec:exec':

eclipselink-module-path-test.zip

I think the problem is that DBPlatformHelper is trying to read 'org/eclipse/persistence/internal/helper/VendorNameToPlatformMapping.properties' using ClassLoader.getResourceAsStream but since package 'org.eclipse.persistence.internal.helper' is not opened unconditionally, getResourceAsStream returns null.

From getResourceAsStream javadoc:
"... this method will only find resources in packages of named modules when the package is opened unconditionally."

I guess, a quick fix for this would be to add:

opens org.eclipse.persistence.internal.helper;

to org.eclipse.persistence.core's module-info.java

@nedseb
Copy link

nedseb commented May 11, 2022

I have exactly the same issue ! If someone fixes it, I will be more than grateful

lukasj added a commit to lukasj/eclipselink that referenced this issue Jun 2, 2022
…pp using module path

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
lukasj added a commit that referenced this issue Jun 2, 2022
…ule path

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants