users@glassfish.java.net

Re: How to make Toplink Essentials robust to lost DB connections?

From: <glassfish_at_javadesktop.org>
Date: Tue, 08 Apr 2008 20:53:11 PDT

Thank you for your answer but if my guess is right, the glassfish example implies that transaction type is JTA. Or in any case it's a container managed connection pool.
In my case the transaction type is RESOURCE_LOCAL as there is no JTA context. Moreover I can't even use Tomcat's non-JTA datasource (see number 4 in my previous post) and here is why:
I'd have to have something like the following in my persistence.xml:

 <persistence-unit name="SamplePU" transaction-type="RESOURCE_LOCAL">
   <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
   [b]<non-jta-data-source>java:comp/env/jdbc/DefaultDS</non-jta-data-source>[/b]
   <class>sample.MyEntity</class>
   <properties>
     <property name="toplink.session.customizer" value="es.claro.commons.ds.DataSourceSessionCustomizer"/>
   </properties>
 </persistence-unit>

The problem is that I can't keep the property in [b]bold[/b] above in persistence.xml because I need to be able to set the value from a different configuration file. This is because the jar file with persistence.xml is shared between multiple web applications and located in Tomcat's lib folder.

Thus the only option I have is to use the following persistence.xml:

  <persistence-unit name="PU" transaction-type="RESOURCE_LOCAL">
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <properties>
      <property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/db"/>
      <property name="toplink.jdbc.user" value="xxx"/>
      <property name="toplink.jdbc.password" value="xxx"/>
    </properties>
  </persistence-unit>

I can override <property> tags' values when calling Persistence.createEntityManagerFactory() and thus it works in the environment where the jar file is shared between multiple web applications.

So, persistence.xml I'm using causes Toplink to use its internal connection pool. And that pool has no configuration options other than min and max read and write connection numbers.

How to make Toplink reestablish broken connections in Java SE environment?
[Message sent by forum member 'sultanbek' (sultanbek)]

http://forums.java.net/jive/thread.jspa?messageID=268280