JPA EntityManagerFactory with persistence.xml and Properties Map

Can I pass some properties to EntityManagerFactory by code, while maintaining persistence.xml as the main configuration source? Using createEntityManager overloads using Map looks completely overriding persistence.xml :

 Map<String, String> propertyMap; factory.createEntityManager(propertyMap); 

I would like to configure JPA in persistence.xml , but pass to the user connection string. I use HSQL, and I would like to make my own path to the DB file with the current user directory, which I need to get by the code (as far as I know).

It would be great if I could save persistence.xml anyway, since I would not have to write a custom configuration mechanism.

+4
source share
1 answer

You mean

 Persistence.createEntityManagerFactory(puName, props); 

Unless, of course, you mean that you created EMF in the first place and want to apply the details after that?

+3
source

Source: https://habr.com/ru/post/1412934/


All Articles