Note that there are some explanatory texts on larger screens.

plurals
  1. POPortable JPA application without specifying database username and password inside persistence.xml
    primarykey
    data
    text
    <p>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 <a href="http://foobar.lu/wp/2010/12/30/change-jpa-entitymanager-connection-properties-at-runtime/" rel="nofollow">link here</a></p> <p>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.</p> <p>This is the code I am working with</p> <pre><code>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"); </code></pre> <p>the code above throws an exception</p> <p>This is my persistence.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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"&gt; &lt;persistence-unit name="SADPU" transaction-type="RESOURCE_LOCAL"&gt; &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt; &lt;class&gt;sad.entity.Credential&lt;/class&gt; &lt;class&gt;sad.entity.Customer&lt;/class&gt; &lt;class&gt;sad.entity.Employee&lt;/class&gt; &lt;class&gt;sad.entity.HourlyRate&lt;/class&gt; &lt;class&gt;sad.entity.Item&lt;/class&gt; &lt;class&gt;sad.entity.Product&lt;/class&gt; &lt;class&gt;sad.entity.ProductTransaction&lt;/class&gt; &lt;class&gt;sad.entity.Province&lt;/class&gt; &lt;class&gt;sad.entity.Tax&lt;/class&gt; &lt;class&gt;sad.entity.TransactionParticular&lt;/class&gt; &lt;class&gt;sad.entity.WorkingHours&lt;/class&gt; &lt;class&gt;sad.entity.Zero&lt;/class&gt; &lt;/persistence-unit&gt; </code></pre> <p>After setting the persistence unit I created the entity manager with</p> <pre><code>Persistence.createEntityManagerFactory("SADPU", map); </code></pre> <p>I removed the properties tags to test if I can achieve what I want but it throws an exception</p> <blockquote> <p>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</p> </blockquote> <p>Am I doing it wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload