Is there a way to make the data on the persistence.xml dynamic? I was thinking of adding a database name property on my properties file, then the tables are created, if not existing.
Is this possible?
I'm using EclipseLink(JPA2.0) and MySQL.
Is there a way to make the data on the persistence.xml dynamic? I was thinking of adding a database name property on my properties file, then the tables are created, if not existing.
Is this possible?
I'm using EclipseLink(JPA2.0) and MySQL.
If you use JPA in standalone environment, you can pass additional properties to Persistence.createEntityManagerFactory()
.
In application server environments you can use datasource obtained from JNDI.
If you are using spring, you can use the spring property-placeholder-configurer
mechanism to do so. Just extend your EclipseLink vendor adapter:
public class ExtendedJpaVendorAdapter extends XJpaVendorAdapter {
private Map<String, Object> vendorProperties;
@Override
public Map<String, Object> getJpaPropertyMap() {
Map<String, Object> properties = super.getJpaPropertyMap();
properties.putAll(vendorProperties);
return properties;
}
public Map<String, Object> getVendorProperties() {
return vendorProperties;
}
public void setVendorProperties(Map<String, Object> vendorProperties) {
this.vendorProperties = vendorProperties;
}
}
And then you can configure these in the spring xml file.