Quantcast

Built in DBCP pooling stopped working after upgrade to 2.2.0

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Built in DBCP pooling stopped working after upgrade to 2.2.0

Fredrik Jonson
Hi All,

I have a webapp that use the built in DBCP pooling against postgresql. It
works just fine under openjpa 2.1.1 but when I try to upgrade to 2.2.0 it
fails.

Here's my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
  <persistence-unit name="quux-postgresql" transaction-type="RESOURCE_LOCAL">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <class>org.example.Foo</class>
    <properties>
      <property name="openjpa.ConnectionDriverName" value="org.postgresql.Driver"/>
      <property name="openjpa.ConnectionURL" value="jdbc:postgresql://localhost/foo"/>
      <property name="openjpa.ConnectionUserName" value="foo"/>
      <property name="openjpa.ConnectionPassword" value="foo"/>
      <property name="openjpa.jdbc.DriverDataSource" value="dbcp"/>
      <property name="openjpa.jdbc.DBDictionary" value="postgres"/>
      <property name="openjpa.Log" value="DefaultLevel=TRACE"/>
      <property name="openjpa.DynamicEnhancementAgent" value="false"/>
      <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
    </properties>
  </persistence-unit>
</persistence>

My unit test hardly starts before it fails:

public class FooServiceTest
{
    @Test
    public void canPersist()
    {
        EntityManagerFactory factory =
            Persistence.createEntityManagerFactory("quux-postgresql");
        EntityManager em = factory.createEntityManager();
    }
}

When I remove the line with pooling config, "DriverDataSource=dbcp", non-pooled
connectivity works and the test passes, so there is nothing wrong with my
database conection or the postgresql driver as far as I can tell. And as
mentioned, if i instead keep the dbcp flag and downgrade to 2.1.1, the
configuration above again works fine.

I have tried various dependency combinations. With and without a explicit
dependency on commons-dbcp 1.4, and with the openjpa and the openjpa-all
artifacts. No difference.

What seems strange is that I get the following error message at the end of the
stacktrace:

  NoSuchMethodException:
  org.apache.openjpa.jdbc.schema.DBCPDriverDataSource.newInstance()

<openjpa-2.2.0-r422266:1244990 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: <openjpa-2.2.0-r422266:1244990 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "org.postgresql.Driver" and URL "jdbc:postgresql://localhost/foo".  You may have specified an invalid URL.
        at org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:255)
        at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:123)
        at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:844)
        at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:732)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:295)
        at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1671)
        at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:646)
        at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:203)
        at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
        at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
        at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
        at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
        at org.example.FooServiceTest.before(FooServiceTest.java:24)
Caused by: org.apache.commons.lang.exception.NestableRuntimeException: An instance of the class "class org.apache.openjpa.jdbc.schema.DBCPDriverDataSource" could not be instantiated.  Make sure the class has a public no-args constructor.
        at org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.java:240)
        at org.apache.openjpa.lib.conf.ObjectValue.newInstance(ObjectValue.java:124)
        at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:103)
        at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
        at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.newDriverDataSourceInstance(JDBCConfigurationImpl.java:639)
        at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:89)
        ... 46 more
Caused by: java.lang.InstantiationException: java.lang.NoSuchMethodException: org.apache.openjpa.jdbc.schema.DBCPDriverDataSource.newInstance()
        at org.apache.openjpa.lib.util.J2DoPrivHelper$11.run(J2DoPrivHelper.java:377)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.java:234)

--
Fredrik Jonson

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Built in DBCP pooling stopped working after upgrade to 2.2.0

allee8285
This is a regression. https://issues.apache.org/jira/browse/OPENJPA-2153 opened to address the issue.
Loading...