4

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.

Matthias Meid
  • 12,455
  • 7
  • 45
  • 79
  • I would load the properties from persistence.xml, replace/add the desired values and create the entitymanager from the properties. – SJuan76 May 17 '12 at 08:32

1 Answers1

3

You mean

Persistence.createEntityManagerFactory(puName, props);

unless of course you mean you have created the EMF first and want to apply props after that?

DataNucleus
  • 15,497
  • 3
  • 32
  • 37