It depends on how you load your EntityManagerFactory. Each of the two specified methods allows you to pass the value of java.util.Map values. It is assumed that these values ​​take precedence over values ​​defined in a constant unit.
There is no problem with the SE approach, since the boot process is usually controlled by your application: javax.persistence.Persistence#createEntityManagerFactory(String puName, Map config . Now you may have problems if something else (ahh, Spring) " Manages EMF for you ...
In the "EE-approach" I do not know a good global approach. This value map still exists at boot time, but the problem is that the EE container is the one that calls this method.
One Hibernate-specific approach that would work anyway would be to replace configuration variables. Thus, on your persistence device, you must define a username or password using ${some.key} , and Hibernate will replace them for you. Whether this will work really depends on how you want to ultimately set these values; Hibernate still needs to access the configuration value named some.key for this to work ...
Another “global approach” ... The “EE Approach” for loading EMF is a container for instantiating javax.persistence.spi.PersistenceProvider and calling its javax.persistence.spi.PersistenceProvider # createContainerEntityManagerFactory. createContainerEntityManagerFactory has an interesting signature here. Essentially, it is passed to javax.persistence.spi.PersistenceUnitInfo, which is an object representation of the analyzed persistence unit plus some other things. An option would be to use this approach for bootstrapping and pass into the javax.persistence.spi.PersistenceUnitInfo instance that you are creating yourself. javax.persistence.spi.PersistenceProvider is an interface. To create an instance, you need to know the provider you want to use, and the FQN to implant them. But this is usually not a problem, as they are pretty well known.
You specifically ask about creating / joining JDBC connections. You have additional features. You may have your "accounting service" creating DataSources, and your JPA provider simply uses this DataSource. All JPA providers support data source lookups through JNDI lookups. In "EE download", DataSource can also be passed to providers for use through PersistenceUnitInfo # getJtaDataSource and / or PersistenceUnitInfo # getNonJtaDataSource. Hibernate takes an instance of the DataSource one at a time instead of the typical DataNource JNDI data name. If you do not want to use a DataSource (for some odd reason), the alternative to Hibernate is to implement the Hibernate ConnectionProvider contract yourself, this is a contract (interface). Hibernate uses to receive and release JDBC connections when necessary. By implementing ConnectionProvider, you can configure basic Connections in any way you like.
Lots of options :)
Steve ebersole
source share