« Basics of using JRA with WLS | Main | XML Entity Caching in WebLogic Server »

JPA and WLS JDBC Configuration

While not strictly related to performance I did come across an interesting tidbit today that I think is worth sharing.   I have been working with JPA based application that has a persistence.xml that is set up to provide the person deploying the application with some flexibility when defining the data sources.  

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
  <persistence-unit name="Order">
    <jta-data-source>jdbc/OrderDS</jta-data-source>
    <class>foo.bar.orders.Customer</class>
    <class>foo.bar.orders.Order</class>
    <class>foo.bar.orders.OrderLine</class>
  </persistence-unit>
  <persistence-unit name="Mfg">
    <jta-data-source>jdbc/MfgDS</jta-data-source>
    <class>foo.bar.mfg.Assembly</class>
    <class>foo.bar.mfg.Component</class>
    <class>foo.bar.mfg.Inventory</class>
    <class>foo.bar.mfg.WorkOrder</class>
  </persistence-unit>
</persistence>

The first reaction when confronted with this descriptor might be to deploy multiple connection pools one for each persistence unit.  This may even be appropriate in some cases because if could be that you are actually going to different back end systems. 

If you happen to know that you are actually hitting the same back end database you may think that your only choice is to modify the persistence.xml to point them to a common data source.  Fortunately, WLS provides the flexibility of providing multiple jndi names for each data source.  

<jdbc-data-source xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <name>specjds-jdbc</name>
  <jdbc-driver-params>
    <url>@DATABASE_URI@</url>
    <driver-name>@DATABASE_DRIVER@</driver-name>
    <properties>
      <property>
        <name>user</name>
        <value>@DATABASE_USER@</value>
      </property>
      <property>
        <name>password</name>
        <value>@DATABASE_PASSWORD@</value>
      </property>
  </jdbc-driver-params>
  <jdbc-connection-pool-params>
    <initial-capacity>32</initial-capacity>
    <max-capacity>64</max-capacity>
    <capacity-increment>4</capacity-increment>
    <statement-cache-size>128</statement-cache-size>
  </jdbc-connection-pool-params>
  <jdbc-data-source-params>
    <jndi-name>jdbc/OrderDS</jndi-name>
    <jndi-name>jdbc/MfgDS</jndi-name>
  </jdbc-data-source-params>
</jdbc-data-source>

This is a handy way of mapping from JPA onto your database configuration without having to perform any manipulation of the descriptors that are embedded inside the application archive.

 

 

TrackBack

TrackBack URL for this entry:
http://blogs.oracle.com/mt/mt-tb.cgi/12815

Comments (1)

Can anyone recommend the best Remote Management utility for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: N-able N-central internet security software
? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on July 9, 2009 8:37 PM.

The previous post in this blog was Basics of using JRA with WLS.

The next post in this blog is XML Entity Caching in WebLogic Server.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle