Have EntityManagerFactory expose persistence.xml `jta-data-source` element as a `javax.persistence.nonJtaDataSource` property

Description

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.

Environment

None

Activity

Show:
Phillip Webb
October 2, 2019, 2:40 AM

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.

Steve Ebersole
October 2, 2019, 7:22 AM

That approach misses a DataSource supplied by integration overrides...

Sanne Grinovero
October 2, 2019, 7:28 AM

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.

Steve Ebersole
October 2, 2019, 8:13 AM

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

Gail Badner
January 7, 2020, 10:08 PM

Fixed in 5.3 branch as well.

Assignee

Steve Ebersole

Reporter

Phillip Webb

Fix versions

Labels

None

backPortable

Backport?

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor
Configure