-
Notifications
You must be signed in to change notification settings - Fork 178
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
Allow eclipselink config outside classpath #95
Allow eclipselink config outside classpath #95
Conversation
@@ -124,7 +124,7 @@ private Map<String, String> loadProperties(String confFile, String persistenceUn | |||
} | |||
|
|||
try { | |||
InputStream input = this.getClass().getClassLoader().getResourceAsStream(confFile); | |||
FileInputStream input = new FileInputStream(confFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine but Persistence.createEntityManagerFactory(persistenceUnitName, properties) puts the limitation which can only loads the configuration from a jar. I'm making a change to workaround that. #88
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to fix this in the last commit. Please see the this comment in #79
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replied in another thread.
@guitcastro Actually it's not because of the properties. Of course we need the properties because we want to replace realm in the database name - each realm will have its own database.
Persistence.createEntityManagerFactory() will still load configuration file from resource even without properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aihuaxu only if you specify the ECLIPSELINK_PERSISTENCE_XML
property. I've tested and it worked.
From their docs:
This property is only used by EclipseLink when it is locating the configuration file.
When used within an EJB/Spring container in container managed mode the locating and reading of this file is done by the container and will not use this configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added unit test to ensure config loads from outside the classpath is working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guitcastro Can you list the steps how you get it to work? It's possible the unit test found the persistence.xml from the embedded jar. That's why it doesn't fail for you.
I don't see the changes or unit tests in the PR. Did you forget to include that?
I only see
properties.put(ECLIPSELINK_PERSISTENCE_XML, confFile); -- removed
FileInputStream input = new FileInputStream(confFile);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aihuaxu Sorry, I have forgot to push it. Can you please take a look now? I also added a test to ensure that the config is not being loaded from the classpath.
This looks similar to #79, which did not work when tested. |
I fix this in the last commit. Please see the this comment in #79 |
Hi @guitcastro, I tested this change and found that it did not work. See my notes below: I copied the default
I then modified the default
If I revert the default Based on this, I suspect that your change is in fact just loading the default |
Maybe the |
} | ||
|
||
@Test | ||
void ensureNotLoadingDefaultClassPersistence() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this test that you're not still loading the file from /META-INF/persistence.xml
?
No @guitcastro it was definitely there -- like I mentioned, I copied it directly from the existing default file. Have you done an end-to-end test using this change including bootstrapping Polaris? If so can you share the steps? |
PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl(); | ||
PolarisEclipseLinkStore store = new PolarisEclipseLinkStore(diagServices); | ||
PolarisEclipseLinkMetaStoreSessionImpl session = | ||
new PolarisEclipseLinkMetaStoreSessionImpl( | ||
store, Mockito.mock(), () -> "realm", null, "polaris-dev"); | ||
store, Mockito.mock(), () -> "realm", tmpFile.toString(), "polaris-dev"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this, Persistence.createEntityManagerFactory() will use the one in the jar, not the /tmp/%s-persistence.xml.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can try to remove persistence.xml from the project and see the issue.
@aihuaxu @eric-maynard You are right, what happened is that my external configuration had a persistence unit also named |
Yeah. So let's move forward with my workaround solution for now until we have a better one? |
Description
As today, It's impossible to load configurations outside the classpath using eclipse-link. This PR allow do load config files from any path.
Fixes # (issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
I've update the
PolarisEclipseLinkMetaStoreTest
to ensure that the file is being loaded from outside the classpath.Checklist:
Please delete options that are not relevant.