Can I pass some properties to an EntityManagerFactory
by code, while still maintaining persistence.xml
as the main configuration source? Using createEntityManager
's overload with a Map
appears to override persistence.xml
completely:
Map<String, String> propertyMap;
factory.createEntityManager(propertyMap);
I'd like to configure JPA in persistence.xml
, but pass in a custom connection string. I'm using HSQL and I'd like to compose a custom DB-file path with the current user directory, which I have to get by code (as far as I know).
It would be great if I could keep persistence.xml
anyway, as I'd not have to write a custom configuration mechanism.
You mean
Persistence.createEntityManagerFactory(puName, props);
unless of course you mean you have created the EMF first and want to apply props after that?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.