In Hibernate 4.3.x the following code would return a non-null DataSource:
In Hibernate 5 this no longer appears to work. The EntityManagerFactoryBuilderImpl contains the following line which seems to suggest that the property should be exposed but, as far as I can tell, the configurationValues are no longer copied to the EntityManagerFactory properties. I wonder if instead ssrBuilder.applySetting should now be used?
This issue was originally identified by a Spring Boot user and more background can be found here. The user has also attached a project that replicates the issue when FirstDbConfig and SecondDbConfig are edited to remove his workaround.
I’ve now fixed the original Spring Boot issue by directly looking at the persistenceUnitInfo so whatever you decide here, Spring Boot users won’t be affected.
That approach misses a DataSource supplied by integration overrides...
Is <jta-data-source/> a property?
Personal opinion is I’d not see it as a property. But the spec seems to “workaround” the otherwise lacking capability to override such “non properties” at boot - so I’d think there’s no harm in exposing such configuration aspects as a property too.
But happy to leave this unspecified, especially since other relevant frameworks seem to no longer need it - assuming is fine with the limitation of Datasource that Steve just pointed out.
The approach I took in the work I’ve done on this over the past few days was that EMF#getProperties exposes al effective properties. This includes a DataSource specified via <jta-data-source/> or <non-jta-data-source/> in persistence.xml
If you wish to play with this work, see
Fixed in 5.3 branch as well.