commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Ward <>
Subject Re: Can't get MySQL non-jta connection pool with Aries-2.4.0 and EL-2.6.2 working - Looking for (more) example(s).
Date Mon, 25 Jul 2016 14:12:09 GMT

Have you considered using Aries Transaction Control? It's typically much simpler to configure
than the raw JDBC service, and it definitely gives you connection pooling (again, without
extra moving parts).

Best Regards,

Tim Ward

Sent from my iPhone

On 24 Jul 2016, at 21:51, Erwin Hogeweg <<>>


Not sure if this is a question for these lists or for the EL list but I figure I start here.
Feel free to redirect when you feel it doesn’t belong here.

I am trying to get a non-jta connection pool (internal connection pool) working with EL 2.6.2,
Aries 2.4.0 (incl. EL adapter), dbcp2-2.1 and mySQL, but I must be missing something because
I just can’t get it to work properly. Everything works just fine w/o a connection pool,
so this is definitely the source of the misery.

Been struggling with this for a while now, and I am running out of ideas. I think I could
use some sample code to point me in the right direction that doesn't use Blueprint? I found
some of Christian’s examples, but I don’t think they are using connection pools.

Below a short summary of what I run into.

When I am using the ‘original’ MysqlDataSource...

    private DataSource createMySQLDataSource( Dictionary<String, String> dbConnProps
) {
        MysqlDataSource ds = new MysqlDataSource();
        ds.setUrl( dbConnProps.get( "jdbc_url" ) );
        ds.setUser( dbConnProps.get( "jdbc_user" ) );
        ds.setPassword( dbConnProps.get( "jdbc_password" ) );
        return ds;

… everything kinda works normally. The DataSource, PersistenceProvider and EntityManagerFactory
are all created and registered correctly;

g! services javax.sql.DataSource
{javax.sql.DataSource}={,,, service.bundleid=104, service.scope=singleton}
  "Registered by bundle:" [104]

g! services javax.persistence.EntityManagerFactory
osgi.unit.provider=org.eclipse.persistence.jpa.PersistenceProvider,, service.bundleid=98,
  "Registered by bundle:" [98]

The performance is horrible though as I don’t really seem to get a connection pool. The
connection is closed after every query. On top of that I loose all network connections every
few seconds with a:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Which has me puzzled for a while now.

So my next attempt was to use the org.apache.commons.dbcp2.BasicDataSource:

   private DataSource createMySQLDataSource(  Dictionary<String, String> dbConnProps
) {

    BasicDataSource basicDataSource = new BasicDataSource();
        return basicDataSource;

This fails because the following exception:

[EL Severe]: 2016-07-24 14:41:55.872--java.lang.UnsupportedOperationException: Not supported
by BasicDataSource
at org.apache.commons.dbcp2.BasicDataSource.getConnection(

Which is this method:

    public Connection getConnection(String user, String pass) throws SQLException {
        // This method isn't supported by the PoolingDataSource returned by
        // the createDataSource
        throw new UnsupportedOperationException("Not supported by BasicDataSource");

So I figured I create a version with a PoolingDataSource  (following the PoolingDataSourceExample
in svn):

        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(dbConnProps.get(
"jdbc_url" ), "user", "password");
        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
    ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory);
        PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(connectionPool);
        return dataSource;

But that still gives me an exception:

[EL Severe]: 2016-07-24 16:40:30.392--java.lang.UnsupportedOperationException
at org.apache.commons.dbcp2.PoolingDataSource.getConnection(

So I am kinda lost now.

This is the relevant stuff from the persistence.xml file:


<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://my_db_server:3306/myschema"
<property name="javax.persistence.jdbc.user" value="user" />
<property name="javax.persistence.jdbc.password" value="password" />
<!-- Configure connection pool. -->
<property name="eclipselink.connection-pool.default.initial" value="10" />
<property name="eclipselink.connection-pool.default.min" value="16" />
<property name="eclipselink.connection-pool.default.max" value="50" />

Although I only see one DataSource registered it somehow feels like there is some more stuff
going on behind the (EL?) scenes that I don’t have a handle on yet.

BTW... I have also created an configuration file, but when
I leave the DB properties out of the persistence.xml I get bunch of ClassNotFound exceptions,
so that is suspicious.

BTW2… the examples link at the bottom of this page is broken:



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message