Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Anyone using EL with newer Tomcat Servlet Environment and JNDI datasource?

Yes, it works.
But you need a "trick" (I've adapted from example available in the Internet - but I lost the reference):

package my.pack;

import javax.naming.InitialContext;
import org.eclipse.persistence.config.SessionCustomizer;
import org.eclipse.persistence.sessions.Connector;
import org.eclipse.persistence.sessions.JNDIConnector;
import org.eclipse.persistence.sessions.Session;

public class JPACustomizer implements SessionCustomizer {

  public JPACustomizer() {
  }

  @Override
  public void customize(Session session) throws Exception {
    JNDIConnector connector;

    try {
      new InitialContext();
      Connector conn = session.getLogin().getConnector();

      if (conn instanceof JNDIConnector) {
        connector = (JNDIConnector) conn; // possible CCE
        connector.setLookupType(JNDIConnector.STRING_LOOKUP);
      }

    } catch (Exception e) {
      Util.debug(e);
    }
  }
}


then in configuration file, you will have to put (inside properties):

<persistence-unit name="SimuladorFretePU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:comp/env/jdbc/myDataSource</non-jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
    <shared-cache-mode>ALL</shared-cache-mode>
    <validation-mode>NONE</validation-mode>
    <properties>
<property name="eclipselink.session.customizer" value="my.pack.JPACustomizer"/>
...


Kind regards,

Edson Richter


On 15-10-2014 10:31, Markus Kolb wrote:
Hello,
does anyone use current EclipseLink version with a up-to-date Tomcat Servlet Container and JNDI non-jta-datasource?
I try to get this working for some hours now...
- EclipseLink 2.5.2 (also tried 2.5.0)
- Tomcat 8.0.14 (but also 7.0.40 tried)

The Tomcat configuration is working. I can lookup the datasource in my application code. But EclipseLink throws a NullPointerException in its JNDIConnector.connect(...). I've reported this as https://bugs.eclipse.org/bugs/show_bug.cgi?id=447264

I've also tried https://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial#Session_Customizer.
Result: Same NPE.

I'm using now a Jetty Container 9.2.3 with EclipseLink 2.5.2 and the same WAR just works.

Is there any trick to get this working in Tomcat?

Thanks
Markus
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-users





Back to the top