Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » connecting an application to two different JNDI datasources(I am having trouble configuring my application to connect to two different datasources)
connecting an application to two different JNDI datasources [message #634742] Fri, 22 October 2010 22:47 Go to next message
Patricia Goldweic is currently offline Patricia GoldweicFriend
Messages: 34
Registered: October 2010
Member
I'm trying to configure a Java SE app running under Tomcat 6 and using JPA, to connect to two different JNDI datasources. I've followed the instructions in the article at http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_ Tutorial#JNDI_Datasource_Setup, but I'm defining two of each (2 'resource-ref' and 'persistence-context-ref' elements in web.xml, 2 different <resource> elements within the GlobalNamingResources tag in server.xml, and also 2 <resource-link> elements within the Context element in server.xml). However, when I run the program, only one of the data sources (the first one tried) is connected and deployed successfully, while the other one fails to connect with the following exception:
[EL Severe]: 2010-10-22 16:20:22.16--ServerSession(10202447)--Thread(Thread[http-868 6-1,5,main])--Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
Error Code: 0
at org.eclipse.persistence.exceptions.DatabaseException.sqlExce ption(DatabaseException.java:309)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIC onnector.java:138)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIC onnector.java:94)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDa tasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.databaseaccess.DatasourceAc cessor.connectInternal(DatasourceAccessor.java:327)
NOTE: there is authentication and driver information defined for BOTH datasources in the Tomcat file, so this cannot be the real problem. Moreover, I've seen that one of the databases actually ended up, at some point during my experimentation, with tables that correspond to the *other* database.
So, the basic question is: can we actually use eclipselink for an app that needs to connect to 2 distinct datasources? If so, how do you get this to work? Thanks in advance for any suggestions.
Re: connecting an application to two different JNDI datasources [message #635093 is a reply to message #634742] Mon, 25 October 2010 15:44 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Please include the persistence.xml that you are using, and code you are using to connect.

It seems that you have not set the jdbc properties on the second persistence unit.


James : Wiki : Book : Blog : Twitter
Re: connecting an application to two different JNDI datasources [message #635374 is a reply to message #635093] Tue, 26 October 2010 15:31 Go to previous messageGo to next message
Patricia Goldweic is currently offline Patricia GoldweicFriend
Messages: 34
Registered: October 2010
Member
Well, the resource properties are being set within the server.xml file in Tomcat, as follows:
-------------------------------------------------------
<GlobalNamingResources>
<Resource name="ds/MySQLDashboard" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" username="dashboard" password="pass" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://somehost:3306/dashboarddev?autoReconnect=true" />
<Resource name="ds/MySQLGint" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" username="dashboard" password="pass"
driverClassName="com.mysql.jdbc.Driver" url=" jdbc:mysql://somehost:3306/gintdashboarddev?autoReconnect=tr ue" />

</GlobalNamingResources>
---------------------------------------------------------
In web.xml, I have the following defined:
---------------------------------------------------------

<!-- Persistence Contexts -->
<persistence-context-ref>
<persistence-context-ref-name>persistence/em1</persistence-context-ref-name >
<persistence-unit-name>GGDashboardTesting</persistence-unit-name >
</persistence-context-ref>

<persistence-context-ref>
<persistence-context-ref-name>persistence/em2</persistence-context-ref-name >
<persistence-unit-name>GintTesting</persistence-unit-name>
</persistence-context-ref>

<resource-ref>
<description>Dashboard DB Connection</description>
<res-ref-name>ds/MySQLDashboard</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

<resource-ref>
<description>Gint DB Connection</description>
<res-ref-name>ds/MySQLGint</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

---------------------------------------------------------


The persistence XML is as follows (note that there are two persistence units):

-----------------------------------------------
<persistence-unit name="GGDashboardTesting">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider >
<non-jta-data-source>java:comp/env/ds/MySQLDashboard</non-jta-data-source >
<class> ..</class>
<class>..</class>
<properties>
<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.MySQLPlatform "/>
<property name="javax.persistence.nonJtaDataSource" value="java:comp/env/ds/MySQLDashboard"/>
<property name="eclipselink.session.customizer" value=" edu.northwestern.at.bboogle.gint.utils.JPAEclipseLinkSession Customizer "/>
<property name="eclipselink.logging.level" value="FINEST"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>

<persistence-unit name="GintTesting">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider >
<non-jta-data-source>java:comp/env/ds/MySQLGint</non-jta-data-source >
<class>..</class>
..
<class>..</class>
<properties>
<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.MySQLPlatform "/>
<property name="javax.persistence.nonJtaDataSource" value="java:comp/env/ds/MySQLGint"/>
<property name="eclipselink.session.customizer" value=" edu.northwestern.at.bboogle.gint.utils.JPAEclipseLinkSession Customizer "/>
<property name="eclipselink.logging.level" value="FINEST"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
------------------------------------------------------------ ------
Finally, the code I'm using to connect is very simple:
EntityManagerFactory factory = Persistence.createEntityManagerFactory("GGDashboardTesting");
EntityManager manager = factory.createEntityManager

(the same code is used for both persistence units).

Thanks in advance for any help with this, as I cannot figure out what is different between the data sources, or whether there is an inherent limitation within Eclipselink.
Re: connecting an application to two different JNDI datasources [message #635649 is a reply to message #635374] Wed, 27 October 2010 15:34 Go to previous messageGo to next message
Patricia Goldweic is currently offline Patricia GoldweicFriend
Messages: 34
Registered: October 2010
Member
I have more information on this problem now, which I think points further to the possibility of a limitation within elipselink (or Tomcat?). For the purposes of experimentation, I switched around the <resource> element definitions in Tomcat, so that one JNDI resource would actually be connecting to the opposite MySQL database and viceversa. (I wanted to test whether there was something screwed/particular about the connection to the second database: 'dashboarddev'). The result was that the first JNDI resource that gets connected (ds/MySQLGint) still connects without trouble to the opposite database (dashboarddev), while the second JNDI resource again fails to be connected (now to the other database: 'gintdashboarddev' ) with the same exception as before. I believe this points to a problem in either eclipselink or Tomcat. Suggestions, confirmations anyone?
Re: connecting an application to two different JNDI datasources [message #635877 is a reply to message #635649] Thu, 28 October 2010 13:17 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

Since the exception is comming from Tomcat when EclipseLink is attempting to get a connection from the datasource, I don't believe its an EclipseLink problem. Have you tried accessing the datasource directly and getting a connection?

Doing a quick search, the issue seems related to:
http://www.theserverside.com/discussions/thread.tss?thread_i d=29795#156653
but someone more familar with Tomcat might be able to help more.

Regards,
Chris
Re: connecting an application to two different JNDI datasources [message #635951 is a reply to message #635877] Thu, 28 October 2010 17:03 Go to previous message
Patricia Goldweic is currently offline Patricia GoldweicFriend
Messages: 34
Registered: October 2010
Member
Thanks for replying. Actually, I don't think that thread is related at all to the point of my question though, since it is about getting one particular JNDI datasource to work at all. I *did* get one to work, so there cannot be a configuration issue. The point is why one datasource works fine, while two togerher don't Sad.
Previous Topic:Trouble converting SQL into JPQL with OUTER JOIN
Next Topic:mapping custom types
Goto Forum:
  


Current Time: Fri Apr 19 22:25:29 GMT 2024

Powered by FUDForum. Page generated in 0.03586 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top