Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Great question; this isn't covered well in the OpenJPA documentation. What you need to do is use the special "java:comp/env/..." syntax for the "openjpa.ConnectionFactoryName" property to ask OpenJPA to retrieve the connection parameters from JNDI. For example, your persistence.xml should look something like this:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;persistence&gt; &lt;persistence-unit name="openjpa"&gt; &lt;provider&gt;org.apache.openjpa.persistence.PersistenceProviderImpl&lt;/provider&gt; &lt;class&gt;tutorial.Animal&lt;/class&gt; &lt;class&gt;tutorial.Dog&lt;/class&gt; &lt;class&gt;tutorial.Rabbit&lt;/class&gt; &lt;class&gt;tutorial.Snake&lt;/class&gt; &lt;properties&gt; &lt;property name="openjpa.ConnectionFactoryName" value="java:comp/env/jdbc/myjndi"/&gt; &lt;property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/&gt; &lt;/properties&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre> <p>This will request a jndi resource called "myjndi" from the container. If you're using Tomcat, you would have a context.xml that looks something like this:</p> <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt; &lt;Context&gt; &lt;Resource name="jdbc/myjndi" auth="Container" scope="Shareable" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" username="username" password="password" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/DBNAME?characterEncoding=UTF-8" /&gt; &lt;/Context&gt; </code></pre> <p>Change the JNDI parameters above as required for your database.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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