I am developing a JPA application for my project. I am using eclipselink. I found this tutorial but it doesn't fit with the complexity of my application link here
I want to create an external file for the username, password and url of the database so that I will not change the persistence.xml file every time i change the username and password, or the hostname of the db.
This is the code I am working with
Map map = new HashMap();
map.put(PersistenceUnitProperties.JDBC_USER, "root");
map.put(PersistenceUnitProperties.JDBC_PASSWORD, "toor");
map.put(PersistenceUnitProperties.JDBC_URL, "jdbc:mysql://localhost:3306/sad?zeroDateTimeBehavior=convertToNull");
map.put(PersistenceUnitProperties.JDBC_DRIVER, "com.mysql.jdbc.Driver");
the code above throws an exception
This is my persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="SADPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>sad.entity.Credential</class>
<class>sad.entity.Customer</class>
<class>sad.entity.Employee</class>
<class>sad.entity.HourlyRate</class>
<class>sad.entity.Item</class>
<class>sad.entity.Product</class>
<class>sad.entity.ProductTransaction</class>
<class>sad.entity.Province</class>
<class>sad.entity.Tax</class>
<class>sad.entity.TransactionParticular</class>
<class>sad.entity.WorkingHours</class>
<class>sad.entity.Zero</class>
</persistence-unit>
After setting the persistence unit I created the entity manager with
Persistence.createEntityManagerFactory("SADPU", map);
I removed the properties tags to test if I can achieve what I want but it throws an exception
Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform
Am I doing it wrong?