0

I have a application with JPA Hibernate without Spring and I need connect to multiple databases (with the same estructure).

The databases will be created for each client, and would have to use the same entity manager. Please I need some idea of ​​how I can do that. I am not using Spring. My application uses MySql, JPA2, Hibernate and JSF.

Thank you!

asked Jun 29, 2012 at 15:27

1 Answer 1

1

If everything is the same, except for dbname/username/pass, then create a persistence.xml with a persistance unit, put everything there which is static.

Then use the following method to create the entity manager:

javax.persistence.Persistence.createEntityManagerFactory(String persistenceUnitName, Map properties);

Supply the variable parameters in the map, like this:

properties.put("hibernate.connection.url", "jdbc:postgresql://127.0.0.1/test");
properties.put("hibernate.connection.username", "joe");
properties.put("hibernate.connection.password", "pass");
answered Jun 29, 2012 at 15:39
Sign up to request clarification or add additional context in comments.

1 Comment

Your answer is the solution! Thanks!!. My problem was resolved

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.