I have a persistence.xml file like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="AppPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>util.Pazienti</class>
<class>util.Trattamenti</class>
<class>util.Pagamenti</class>
<class>util.Configurazioni</class>
<class>util.Modpagamenti</class>
<class>ent.Modpagamenti</class>
<class>ent.Configurazioni</class>
<class>ent.Trattamenti</class>
<class>ent.Pagamenti</class>
<class>ent.Pazienti</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:sqlite:/Users/Alice/Library/Application Support/AppName/DB.SQLite"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.driver" value="org.sqlite.JDBC"/>
</properties>
</persistence-unit>
</persistence>
And I'd like to change url path with replacing my username with the correct username (the one which is using the application).
I wrote an "Init" function which should override jdbc:url property
Map<String, String> persistenceMap = new HashMap<>();
persistenceMap.put("javax.persistence.jdbc.url", "jdbc:sqlite:"+DB_FILE_PATH);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("AppPU", persistenceMap);
emf.createEntityManager(persistenceMap);
where
DB_FILE_PATH = System.getProperty("user.home") + File.separator + "Library" + File.separator + "Application Support" + File.separator + "AppName" + File.separator + DB.SQLite;
but it doesn't work raising (long story short): /User/Dave folder not present
, e.g. to simulate an installation in a pc with a user name different from mine I changed jdbc:url replacing "Dave" with (a random name) "Alice".
So, System.getProperty("user.home") = "/Users/Dave"
(which is the current user is running the application, but Hibernate is still looking for "/Users/Alice"
ignoring override and raising:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: path to '/Users/Alice/Library/Application Support/AppName/DB.SQLite': '/Users/Alice' does not exist
Error Code: 0
Java Result: 255
Am I missing something? Any suggestion will be appreciate!