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

Bug in the PersistenceUnitProcessor.findPersistenceArchives(ClassLoader loader, String descriptorPath) - bugfix #1383

Conversation

rfelcman
Copy link
Contributor

@rfelcman rfelcman commented Jan 5, 2022

This small fix allows using/loading persistence.xml from WAR file from .../WEB-INF/classes/META-INF/persistence.xml location in JSE environment.
It is still required to point EclipseLink (EntityManagerFactory) to this location in JSE environment by:

System.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "WEB-INF/classes/META-INF/persistence.xml");
or

Properties persistenceUnitProperties = new Properties(); persistenceUnitProperties.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "WEB-INF/classes/META-INF/persistence.xml"); EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("test-jpa-pu2", persistenceUnitProperties);

Before this fix ValidationException
e.g.

Internal Exception: Exception [EclipseLink-7357] (Eclipse Persistence Services - 4.0.0.v202112161344): org.eclipse.persistence.exceptions.ValidationException Exception Description: URL [jar:file:/tmp/test1348.war!/WEB-INF/classes/META-INF/persistence.xml] for resource [WEB-INF/classes/META-INF/persistence.xml] does not belong to a valid persistence root (as per JPA Specification)

was thrown

Fixes #1348

Signed-off-by: Radek Felcman [email protected]

…er loader, String descriptorPath) - bugfix

This small fix allows using/loading persistence.xml from WAR file from .../WEB-INF/classes/META-INF/persistence.xml location in JSE environment.
It is still required to point EclipseLink (EntityManagerFactory) to this location in JSE environment by:

  System.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "WEB-INF/classes/META-INF/persistence.xml");
or
  Properties persistenceUnitProperties = new Properties();
  persistenceUnitProperties.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "WEB-INF/classes/META-INF/persistence.xml");
  EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("test-jpa-pu2", persistenceUnitProperties);

Before this fix ValidationException
e.g.
Internal Exception: Exception [EclipseLink-7357] (Eclipse Persistence Services - 4.0.0.v202112161344): org.eclipse.persistence.exceptions.ValidationException
Exception Description: URL [jar:file:/tmp/test1348.war!/WEB-INF/classes/META-INF/persistence.xml] for resource [WEB-INF/classes/META-INF/persistence.xml] does not belong to a valid persistence root (as per JPA Specification)

was thrown

Fixes eclipse-ee4j#1348

Signed-off-by: Radek Felcman <[email protected]>
Copy link
Member

@lukasj lukasj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be probably good to add a (unit) test for this class to cover valid/invalid scenarios to have something for the future reference

…er loader, String descriptorPath) - bugfix and unit test

This small fix allows using/loading persistence.xml from WAR file from .../WEB-INF/classes/META-INF/persistence.xml location in JSE environment.
It is still required to point EclipseLink (EntityManagerFactory) to this location in JSE environment by:

  System.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "WEB-INF/classes/META-INF/persistence.xml");
or
  Properties persistenceUnitProperties = new Properties();
  persistenceUnitProperties.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "WEB-INF/classes/META-INF/persistence.xml");
  EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("test-jpa-pu2", persistenceUnitProperties);

Before this fix ValidationException
e.g.
Internal Exception: Exception [EclipseLink-7357] (Eclipse Persistence Services - 4.0.0.v202112161344): org.eclipse.persistence.exceptions.ValidationException
Exception Description: URL [jar:file:/tmp/test1348.war!/WEB-INF/classes/META-INF/persistence.xml] for resource [WEB-INF/classes/META-INF/persistence.xml] does not belong to a valid persistence root (as per JPA Specification)

was thrown

Fixes eclipse-ee4j#1348

Signed-off-by: Radek Felcman <[email protected]>
@rfelcman
Copy link
Contributor Author

rfelcman commented Jan 5, 2022

It would be probably good to add a (unit) test for this class to cover valid/invalid scenarios to have something for the future reference

OK it's done by second commit.

Signed-off-by: Radek Felcman <[email protected]>
Copy link
Member

@lukasj lukasj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rfelcman rfelcman merged commit 9417d47 into eclipse-ee4j:master Jan 7, 2022
rfelcman added a commit to rfelcman/eclipselink that referenced this pull request Jan 10, 2022
…er loader, String descriptorPath) - bugfix (eclipse-ee4j#1383)

Bug in the PersistenceUnitProcessor.findPersistenceArchives(ClassLoader loader, String descriptorPath) - bugfix

This small fix allows using/loading persistence.xml from WAR file from .../WEB-INF/classes/META-INF/persistence.xml location in JSE environment.
It is still required to point EclipseLink (EntityManagerFactory) to this location in JSE environment by:

  System.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "WEB-INF/classes/META-INF/persistence.xml");
or
  Properties persistenceUnitProperties = new Properties();
  persistenceUnitProperties.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "WEB-INF/classes/META-INF/persistence.xml");
  EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("test-jpa-pu2", persistenceUnitProperties);

Before this fix ValidationException
e.g.
Internal Exception: Exception [EclipseLink-7357] (Eclipse Persistence Services - 4.0.0.v202112161344): org.eclipse.persistence.exceptions.ValidationException
Exception Description: URL [jar:file:/tmp/test1348.war!/WEB-INF/classes/META-INF/persistence.xml] for resource [WEB-INF/classes/META-INF/persistence.xml] does not belong to a valid persistence root (as per JPA Specification)

was thrown

Fixes eclipse-ee4j#1348

Signed-off-by: Radek Felcman <[email protected]>
(cherry picked from commit 9417d47)
@rfelcman rfelcman deleted the jpa_bug_1348_BugInThePersistenceUnitProcessorFindPersistenceArchives branch January 10, 2022 14:45
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 this pull request may close these issues.

Bug in the PersistenceUnitProcessor.findPersistenceArchives(ClassLoader loader, String descriptorPath)
2 participants