-
Notifications
You must be signed in to change notification settings - Fork 9
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
Set javax.persistence.jtaDataSource to null, when provided and empty #48
Comments
Hi @ArneLimburg. Excuse me please for the belated answer. To be honest, I wonder about the purpose. I mean, it looks like you're trying to reuse your production
But maybe I overlook something. So can you please help me understanding your case better? p.s. the builds fail if somebody not part of maintainers list is pushing an MR. I have to fix the configuration for these types of MRs. |
Yes, the use case is to use the production persistence.xml in tests. Otherwise you would have to put all your entities into the test persistence.xml explicitly, because they reside not at the same classpath location as the test persistence.xml. I see no problem, using the production persistence.xml for tests, if you change the transaction type and database connection. I guess that's why the property "javax.persistence.transactionType" was specified. |
I guess, those who've written the JPA specification have not though about config update at runtime. It is however another story :) Do you have a stack trace for me to see what happens, when you don't set javax.persistence.jtaDataSource to |
javax.persistence.jtaDataSource can't be set to null, since the annotation has no default value ;-) |
What happens if you update the constructor of public PersistenceUnitDescriptorImpl(final Element element, final Map<String, Object> properties) {
this.properties = new HashMap<>(properties);
classList = new ArrayList<>();
parse(element);
// cannot use JTA
this.properties.remove("javax.persistence.jtaDataSource");
} |
Guess the same will happen.
If that would be ok for you, I'll change the pull request.
|
You're right. the call to Less invasive is better :) // cannot use JTA
if (properties.containsKey("javax.persistence.jtaDataSource")) {
this.properties.put("javax.persistence.jtaDataSource", null);
} I removed So if you don't mind, update your MR to include this change. |
I'll create a new Pull Request for that. |
👍 |
Just updated my proposal to match the pull request |
My persistence.xml looks like
In the test I want to override it with RESOURCE_LOCAL. At least in Hibernate this can be done by setting the following properties:
I want to achieve the same behavior with @PersistenceProperty, but I cannot set the jtaDataSource to null, which is essential (at least for Hibernate).
My proposal is to set the "javax.persistence.jtaDataSource" property value to null, if it is present in the properties and is an empty string. This way, it could be removed by providing an empty string.
The text was updated successfully, but these errors were encountered: