Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify persistence.xml on runtime

I'm developping a program that uses JPA, and I deployed it in a single jar. I wish to modify (or ask to the user, in an menú item) the configuration of the connection data with the database server.

It's possible to modify the data (user, password, ip) of the server "on the fly"?

(I apologize my bad english)

like image 318
neogurb Avatar asked Dec 03 '25 09:12

neogurb


2 Answers

how about making a HashMap<String,Object> containing your options and passing it to Persistence.createEntityManagerFactory("unitName",map)?

From the Docs:

public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties)

Create and return an EntityManagerFactory for the named persistence unit using the given properties.

Source

like image 95
Simiil Avatar answered Dec 06 '25 00:12

Simiil


The JPA spec doesn't allow for dynamic modification of persistence-units. Some implementations may provide an implementation-specific way of defining a persistence-unit dynamically. With DataNucleus JPA we do it as per the foot of this page

like image 22
DataNucleus Avatar answered Dec 05 '25 23:12

DataNucleus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!