views:

399

answers:

2

Hi all. I'm using C3P0 0.9.1.2 to configure data sources for my connection pool.

When context is loading an error is raised. Here is the trace:

java.lang.NoSuchMethodException: com.mchange.v2.c3p0.PoolBackedDataSource.setUserOverridesAsString(java.lang.String)
    at java.lang.Class.getMethod(Class.java:1605)
    at com.mchange.v2.c3p0.cfg.C3P0Config.bindNamedConfigToBean(C3P0Config.java:215)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.initializeNamedConfig(AbstractPoolBackedDataSource.java:89)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.<init>(AbstractPoolBackedDataSource.java:69)
    at com.mchange.v2.c3p0.PoolBackedDataSource.<init>(PoolBackedDataSource.java:37)
    at com.mchange.v2.c3p0.DataSources.pooledDataSource(DataSources.java:267)
    at com.mchange.v2.c3p0.DataSources.pooledDataSource(DataSources.java:246)
    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.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:115)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:435)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:903)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:817)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:881)
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:597)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:366)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:197)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:172)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:158)
    at com.myApp.backoffice.model.CreateSchema.main(CreateSchema.java:8)
java.lang.NoSuchMethodException: com.mchange.v2.c3p0.PoolBackedDataSource.setUserOverridesAsString(java.lang.String)
    at java.lang.Class.getMethod(Class.java:1605)
    at com.mchange.v2.c3p0.cfg.C3P0Config.bindNamedConfigToBean(C3P0Config.java:215)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.initializeNamedConfig(AbstractPoolBackedDataSource.java:89)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.<init>(AbstractPoolBackedDataSource.java:69)
    at com.mchange.v2.c3p0.PoolBackedDataSource.<init>(PoolBackedDataSource.java:37)
    at com.mchange.v2.c3p0.DataSources.pooledDataSource(DataSources.java:267)
    at com.mchange.v2.c3p0.DataSources.pooledDataSource(DataSources.java:246)
    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.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:115)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:435)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:903)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:817)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:197)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:172)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:158)
    at com.myApp.backoffice.model.CreateSchema.main(CreateSchema.java:8)
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schemaCreator' defined in class path resource [CreateSchema.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.hibernate.impl.SessionFactoryImpl] to required type [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for property 'sessionFactory'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [org.hibernate.impl.SessionFactoryImpl] to required type [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for property 'sessionFactory': no matching editors or conversion strategy found
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:197)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:172)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:158)
    at com.myApp.backoffice.model.CreateSchema.main(CreateSchema.java:8)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.hibernate.impl.SessionFactoryImpl] to required type [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for property 'sessionFactory'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [org.hibernate.impl.SessionFactoryImpl] to required type [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for property 'sessionFactory': no matching editors or conversion strategy found
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1288)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1249)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    ... 15 more
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [org.hibernate.impl.SessionFactoryImpl] to required type [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for property 'sessionFactory': no matching editors or conversion strategy found
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:219)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
    ... 19 more

I have googled this issue but I have found nothing. Any idea? Anybody know if there is any bug in c3p0?

<< added on december 10 >> Here are most relevant parts of my Spring XML configuration file:

<!-- Driver Register -->
<bean id="systemProperties" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetClass"> 
        <value>java.lang.System</value>
    </property>
    <property name="targetMethod">
        <value>setProperty</value>
    </property>
    <property name="arguments">
        <list>
            <value>jdbc.drivers</value>
            <value>${jdbc.driverClassName}</value>
        </list>
    </property>
</bean>

<bean id="unpooledRODataSource"
    class="com.mchange.v2.c3p0.DataSources"
    factory-method="unpooledDataSource">
    <constructor-arg value="${jdbc.ro.url}"/>
    <constructor-arg value="${jdbc.ro.username}"/>
    <constructor-arg value="${jdbc.ro.password}"/>
</bean>

<bean id="unpooledRWDataSource" 
    class="com.mchange.v2.c3p0.DataSources"
    factory-method="unpooledDataSource">
    <constructor-arg value="${jdbc.rw.url}"/>
    <constructor-arg value="${jdbc.rw.username}"/>
    <constructor-arg value="${jdbc.rw.password}"/>
</bean>

<bean id="pooledRODataSource" 
    class="com.mchange.v2.c3p0.DataSources"
    factory-method="pooledDataSource">
    <constructor-arg ref="unpooledRODataSource"/>
    <constructor-arg value="readonly"/>
</bean>

<bean id="pooledRWDataSource" 
    class="com.mchange.v2.c3p0.DataSources"
    factory-method="pooledDataSource">
    <constructor-arg ref="unpooledRWDataSource"/>
    <constructor-arg value="readwrite"/>
</bean>

<alias name="pooledRWDataSource" alias="dataSource"/>
<alias name="pooledRODataSource" alias="alternativeDataSource"/>

<bean id="sessionFactory" 
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="hibernateProperties">
     <props>
      <!-- values from properties file -->
      <prop key="hibernate.dialect">${hibernate.dialect}</prop>
      <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
      <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
      <prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop>
      <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
      <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
      <prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
            <prop key="hibernate.validator.apply_to_ddl">${hibernate.validator.apply_to_ddl}</prop>
      <prop key="hibernate.validator.autoregister_listeners">${hibernate.validator.autoregister_listeners}</prop>
     </props>
    </property>
    <property name="dataSource" ref="dataSource"/>
    <!-- using classpath scanning for autodetection of entity classes (when >= spring 2.5.6) -->
    <property name="packagesToScan">
     <list>
      <value>com/myApp/backoffice/model/*/dto/</value>
     </list>
    </property>
    <property name="eventListeners">
     <map>
      <entry key="merge">
       <bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
      </entry>
        </map>
    </property>
    <property name="entityInterceptor" ref="backofficeInterceptor"/>
</bean>

<!-- Transaction manager -->
<bean id="transactionManager" class="com.myApp.persistence.tx.impl.TransactionManagerImpl">
    <property name="timeoutDelayInMillis" value="${session.timeout}"/>
    <property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- Transactional interceptor -->
<bean id="transactionalInterceptor"
    class="com.myApp.persistence.tx.impl.TransactionalInterceptor">
    <property name="transactionManager" ref="transactionManager" />
</bean>
<!-- Assign Transactional interceptor to @Transactional methods -->
<bean class="com.myApp.persistence.tx.TransactionalAutoProxyCreator">
    <property name="transactionalInterceptor" ref="transactionalInterceptor" />
</bean>
+1  A: 

Looks like you're using Spring. It's likely that it's your Spring XML configuration that is incorrect, so it would help if you could post the relevant bits.

Class PoolBackedDataSource clearly has no setUserOverridesAsString method. Maybe you want class ComboPooledDataSource instead?

Mirko Nasato
I've been "out of order" for a few days. I've added to the body of the question the most relevant parts of my Spring XML configuration.
Alberthoven
+1  A: 

It sounds like you're using an older or newer version of a c3p0 jar (commonly used with Hibernate) than expected... try to make sure that all of your dependencies are properly satisfied.

Malaxeur
+1: Make sure that you have the right JAR versions.
Dean J