Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 379397

Summary: Connection pooling does not work for connections created via Gemini JPA
Product: z_Archived Reporter: GianMaria Romanato <gm.romanato>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P2 CC: eclipselink.orm-inbox, edufrazao, juergen.kissner, ronny.voelker, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Sample persistence.xml file
none
diff file with proposed changes none

Description GianMaria Romanato CLA 2012-05-14 06:56:52 EDT
Build Identifier: 2.4.0.v20120327-r11047

When EclipseLink JPA is used in an OSGi container together with Eclipse Gemini JPA, EclipseLink will always use org.eclipse.persistence.sessions.server.ExternalConnectionPool, thus disabling any form of pooling.

If a database driver is registered via DBAccess, Eclipse Gemini JPA will create a wrapper java.sql.DataSource (org.eclipse.gemini.jpa.PlainDriverDataSource)

Later, when EclipseLink JPA configures the session in class org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl, in method void updateLogins(Map m), at lines 1744-1754, the system will check whether the login object is instance of JNDILogin, and it will then decide to disable pooling at line 1754, login.setUsesExternalConnectionPooling(true).





Reproducible: Always

Steps to Reproduce:
1. Create an OSGi application using EclipseLinkJPA and Gemini-JPA
2. Configure the EclipseLink internal pool as explained in the EclipseLink documentation
3. Start the application

No pooling will be used, a new connection will be created for every database operation.
Comment 1 Tom Ware CLA 2012-05-15 14:01:48 EDT
What does your persistence.xml look like?
Comment 2 GianMaria Romanato CLA 2012-05-17 11:34:20 EDT
Created attachment 215785 [details]
Sample persistence.xml file
Comment 3 GianMaria Romanato CLA 2012-05-17 11:38:07 EDT
The attached sample persistence.xml file contains a JDBC URL. 

When I noticed that pooling was disabled I also tried using a different set of properties (those documented in the Javadoc of the Gemini DBAccess implementation for Derby which I am pasting below) hoping that the system would create a datasource instead of using the driver. But unfortunately this did not work: if I omit the URL parameter I get a runtime exception complaining that the URL is missing.


/**
 * A factory for creating Derby network data sources. The properties specified
 * in the create methods determine how the created object is configured.
 * 
 * Sample code for obtaining a Derby network data source:
 * 
 *     ServiceTracker tracker = 
 *         new ServiceTracker(context, DataSourceFactory.class.getName(), null); 
 *     tracker.open();
 *     DataSourceFactory dsf = (DataSourceFactory) tracker.getService(); 
 *     Properties props = new Properties();
 *     props.put(DataSourceFactory.JDBC_SERVER_NAME, "localhost");
 *     props.put(DataSourceFactory.JDBC_PORT_NUMBER, "1527");
 *     props.put(DataSourceFactory.JDBC_DATABASE_NAME, "myDB");
 *     props.put(DataSourceFactory.JDBC_USER, "mike");
 *     props.put(DataSourceFactory.JDBC_PASSWORD, "password");
 *     DataSource ds = dsf.createDataSource(props);
 *
 * This service also supports a URL-based data source. The following 3 properties
 * can be provided instead of the 5 properties above:
 * 
 *     props.put(DataSourceFactory.JDBC_URL, "jdbc:derby://localhost:1527/myDB");
 *     props.put(DataSourceFactory.JDBC_USER, "mike");
 *     props.put(DataSourceFactory.JDBC_PASSWORD, "password");
 */
public class ClientDataSourceFactory extends AbstractDataSourceFactory {
Comment 4 Tom Ware CLA 2012-05-18 09:02:03 EDT
Changing this to a Gemini JPA Enhancement request.

At the moment, Gemini will build a data source from the connection information you provide and pass it in to EclipseLink as a non-jta-datasource.  When EclipseLink is provided a datasource, it makes use of that datasource and allow it to manage itself.

Gemini could provide an option that allowed EclipseLink to manage its own datasources for cases where EclipseLink has access to all the necessary classes.
Comment 5 GianMaria Romanato CLA 2012-05-18 09:30:12 EDT
You mentioned that when "EclipseLink is provided a datasource, it makes use of that datasource and allow it to manage itself".

Is there an OSGi-friendly way to configure EclipseLink so that it obtains a datasource from the container? So far the only option I am aware of consists in programmatically obtaining the datasource and passing it to EclipseLink via the properties map...
Comment 6 GianMaria Romanato CLA 2012-05-18 11:19:10 EDT
In my humble opinion the importance of this issue should not be lowered from major to enhancement, because the lack of proper pooling makes Gemini JPA practically not usable for production. 

If you add that Gemini JPA supports only Eclipse Link, that it is intended to provide the implementation of the OSGi blueprints and that there is no workaround to enable pooling other than dropping Gemini JPA and going for a different approach, I believe that this issue at presents makes Gemini JPA almost useless.
Comment 7 Tom Ware CLA 2012-05-18 14:18:27 EDT
The gemini folks investigated the best way to expose a JDBC driver to EclipseLink and it turns out that our best option may be within EclispeLink after all.

Gemini makes RESOURCE_LOCAL entity managers that have JDBC properties work by wrapping them in its own datasource implementation and passing them back to EclipseLink.  That datasource implementation is not pooled.

We examined the EclipseLink code and it appears as though EclipseLink could provide a property that allows it to do its own pooling of data sources.

The suggested change is in EntityManagerSetupImpl.updateLogins -> roughly the code mentioned above.

        // mainDatasource is guaranteed to be non null - TODO: No it is not, if they did not set one it is null, should raise error, not null-pointer.
        if (!(login.getConnector() instanceof JNDIConnector)) {
            JNDIConnector jndiConnector;
            if (mainDatasource instanceof DataSourceImpl) {
                //Bug5209363  Pass in the datasource name instead of the dummy datasource
                jndiConnector = new JNDIConnector(((DataSourceImpl)mainDatasource).getName());                
            } else {
                jndiConnector = new JNDIConnector(mainDatasource);                                
            }
            login.setConnector(jndiConnector);
/****
NEW CODE HERE
****/
if (!<ECLIPSELINK_USE_DATASOURCE_FOR_INTERNAL_POOL_PROPERTY>){
            login.setUsesExternalConnectionPooling(true);
}
        }

I still consider this an enhancement but am planning on targetting it for our upcoming 2.4 release so we can investigate this solution.  If the solution is much more complex than above, it will likely have to be deferred.
Comment 8 GianMaria Romanato CLA 2012-05-21 03:43:43 EDT
Thank you very much for the effort you put in Eclipse Link and for your  availability to listen to requests from your users, this is really what makes the Eclipse community so special.

By the way, I guess the change should be login.setUsesExternalConnectionPooling(false) rather then true

I'll keep fingers crossed hoping that this fix will land in the 2.4 release.
Comment 9 Eduardo Frazão CLA 2013-01-23 14:24:20 EST
Hi folks. Any progress on this issue? How can we use Gemini JPA in production without a pooled datasource? The only workaround is inject a ready pooled datasource via properties map?
Comment 10 Tom Ware CLA 2013-01-23 15:14:55 EST
FYI: Gemini has an open bug for JTA integration

https://bugs.eclipse.org/bugs/show_bug.cgi?id=356508
Comment 11 Tom Ware CLA 2013-04-03 11:58:03 EDT
Missed 2.5.0.  Deferring.
Comment 12 GianMaria Romanato CLA 2013-05-13 11:12:34 EDT
Still no pooling when Eclipselink is used with Gemini JPA ?

If this is still the case, I believe you took too early the decision to deprecate EclipseLink OSGi support in favor of Gemini JPA as stated here:

http://wiki.eclipse.org/EclipseLink/Examples/OSGi

"The OSGi support provided by EclipseLink is deprecated and has been replaced by the Gemini JPA project."
Comment 13 Tom Ware CLA 2013-05-21 11:12:28 EDT
Created attachment 231263 [details]
diff file with proposed changes

Attaching diff file with proposed changes.

With this change, Gemini users should specify the following persistence unit property to get pooling.

            <property name="eclipselink.connection-pool.force-internal-pool" value="true"/>

Currently discussing with Gemini group what version of EclipseLink makes this change available.
Comment 14 Tom Ware CLA 2013-05-24 11:35:56 EDT
Fix described above checked into 2.5.1 and trunk
Comment 15 Eduardo Frazão CLA 2013-05-24 15:27:30 EDT
This feature will not added on version 2.4?
Comment 16 Tom Ware CLA 2013-05-24 15:50:53 EDT
How are you dependant on 2.4.x?
Comment 17 Eduardo Frazão CLA 2013-05-24 16:16:06 EDT
Well... 2.5.0 is RC2. I think that it will be released soon right? 
No problem in this case. I can wait. After that, I can upgrade my projects to 2.5.1! Thanks by your effort Tom!!
Comment 18 Eclipse Webmaster CLA 2022-06-09 10:33:18 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink