views:

26

answers:

0

I am facing issue to override persistence.xml in jboss and with Hibernate JPA provider, I spent couple of nights but I couldn't solve it. I am using jboss + hibernate + mysql + ejb3. My requirement is I will provide the connection URL and the persistence unit will connect to the DB but it will be dynamically. so my code below. If anyone can help it will be appreciated.

http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">

org.hibernate.ejb.HibernatePersistence java:/MysqlDS

And in the code:

public static EntityManagerFactory createEMF(String dbName) {

    Map<String, Object> properties = new HashMap<String, Object>(); 
    properties.put("hibernate.connection.driver_class", "com.mysql.jdbc.Driver"); 
    properties.put("hibernate.connection.url", "jdbc:mysql://remoteserver/xxxx"); 
    properties.put("hibernate.connection.username", "root"); 
    properties.put("hibernate.connection.password", "root"); 

    return Persistence.createEntityManagerFactory("blayerPU", properties); 
}

but while i run it still connect to mysqlDS configuration (local db server) instead to remoteserver(need to be overridden)