jndi database connection with jpa and eclipselink

前端 未结 5 2003
误落风尘
误落风尘 2021-02-15 11:01

I try to setup a database connection in java with JNDI in combination with eclipseLink/JPA on Tomcat 5.5. I already configured the JNDI resource in web.xml and context.xml.

相关标签:
5条回答
  • 2021-02-15 11:42

    Just add the class JPAEclipseLinkSessionCustomizer to your project and configure the persistence.xml as shown below:

    <persistence-unit name="yourUnit" transaction-type="RESOURCE_LOCAL">
    
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    
        <non-jta-data-source>java:comp/env/jdbc/yourDs</non-jta-data-source>        
    
        <properties>
            <property name="eclipselink.session.customizer" value="com.company.yourproject.yourpackage.JPAEclipseLinkSessionCustomizer"/>        
        </properties>
    
    </persistence-unit>
    

    You need this workaround only for Apache Tomcat.

    0 讨论(0)
  • 2021-02-15 11:50

    Set the datasource URL to "jdbc/myDs"
    <non-jta-data-source>jdbc/myDs</non-jta-data-source>

    0 讨论(0)
  • 2021-02-15 11:50

    Year 2015 actualisation: I not sure Eclipselink SessionCustomizer is required. In my test all work without (Tomcat 7.x, Java 7.x, Eclipselink 2.4.x).

    Some older materials suggest specific problem with Tomcat 5/6 and special way to resolve it.

    0 讨论(0)
  • 2021-02-15 11:56

    I think you need to code a workaround for the javax.naming.NamingException: This context must be accessed throught a java: URL exception as detailed at http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial#Session_Customizer

    Also see this link which debugs through the problem

    http://forums.java.net/jive/message.jspa?messageID=158622

    0 讨论(0)
  • 2021-02-15 11:59

    I hope you could solve the problem with the comments given ...

    I fix it by adding a property "javax.persistence.nonJtaDataSource" with the same value as the element non-jta-data-source

    0 讨论(0)
提交回复
热议问题