0

First of all, I can successfully debug the application in Tomcat without any errors. Of course, I cannot step through GWT client code in Tomcat, thus trying to also deploy on Jetty which gives me that option.

So, I am trying to debug an application that uses GWT (2.4.0) via Jetty in Eclipse, Hibernate 4.1.1 using JPA and c3p0 and I get the following exception.

Caused by: java.lang.ExceptionInInitializerError
at SOMETHING.HibernateUtil.<clinit>(HibernateUtil.java:23)
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:186)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2273)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2269)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1738)
at SOMETHING.HibernateUtil.<clinit>(HibernateUtil.java:20)
... 29 more
Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider]
at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:192)
at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:114)
at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:54)
at org.hibernate.service.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:69)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:176)
... 41 more
Caused by: java.lang.ClassCastException: org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider cannot be cast to org.hibernate.service.jdbc.connections.spi.ConnectionProvider
at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:189)
... 45 more

I've stripped information, such as the RPC call exceptions, inside which the exception occurs.

My HibernateUtil is pretty vanilla:

public class HibernateUtil {

private static final SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;

static {
    try {
        Configuration configuration = new Configuration();
        configuration.configure();
        serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();        
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    } catch (Throwable ex) {
        // Log exception!
        throw new ExceptionInInitializerError(ex);
    }
}

public static Session getSession() throws HibernateException {
    return sessionFactory.openSession();
}

public static SessionFactory get() {
    return sessionFactory;
}
}

My hibernate.cfg.xml is:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
    <!-- Database connection settings -->
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost:3306/dbname?autoReconnect=true</property>
    <property name="connection.username">dbuser</property>
    <property name="connection.password">dbpass</property>
    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>
    <!-- Disable the second-level cache -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>
    <!-- Drop and re-create the database schema on startup -->
    <property name="hibernate.hbm2ddl.auto">update</property>
    <!-- hibernate.cfg.xml -->


    <property name="hibernate.c3p0.min_size">5</property>
    <property name="hibernate.c3p0.max_size">20</property>
    <property name="hibernate.c3p0.timeout">1800</property>
    <property name="hibernate.c3p0.max_statements">50</property>
    <property name="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>
    <property name="hibernate.c3p0.idle_test_period">10</property>
    <property name="hibernate.c3p0.acquire_increment">5</property>
    <!-- no "connection.pool_size" entry! -->    
    <!-- JDBC connection pool (use the built-in) -->
    <!-- <property name="connection.pool_size">1</property> -->  
    <property name="hibernate.transaction.auto_close_session">false</property>

    <!-- Mapping files -->
            <!-- several mapping class files here -->
</session-factory>

The libraries in my WebContent/WEB-INF/lib folder are:

antlr-2.7.7.jar
c3p0-0.9.1.2.jar
commons-collections-3.2.1.jar
commons-logging-1.1.1.jar
dom4j-1.6.1.jar
gwt-oauth2-0.2-alpha.jar
gwt-servlet.jar
hibernate-c3p0-4.1.1.Final.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-4.1.1.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
httpclient-4.1.3.jar
httpcore-4.1.4.jar
javassist-3.15.0-GA.jar
jboss-logging-3.1.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar
log4j-1.2.14.jar
mysql-connector-java-5.1.18-bin.jar

In my Eclipse build path I have hibernate-jpa-2.0-api-1.0.1.Final.jar on top followed by hibernate-core-4.1.1.Final.jar. The rest are Apache Tomcat 6, EAR, GWT SDK 2.4.0, JRE 1.6.0.26, and web app libraries pointing to all the libraries in my lib folder (including hibernate-jpa-2.0-api-1.0.1.Final and hibernate-core-4.1.1.Final). I've tried including c3p0 (hibernate and/or actual library) up on top to no avail. Same error. Also tried slightly older versions of Hibernate 4 libraries but again, same error.

Any ideas?

iliask
  • 535
  • 2
  • 7
  • 18

1 Answers1

0

I believe this is a Jetty Classloader issue. I actually received the same problem when I attempted to use c3p0 to resolve a ClassCastException that resulted from the default ConnectionProvider, and I believe that this problem should have the same solution as this.

Community
  • 1
  • 1
Matt G
  • 106
  • 1
  • 3
  • Thanks Matt and thanks for your prompt response. I did see this bug report and the other SO question during my search but I was not sure where this code should reside, plus there was mention of EJBs and stuff. Any suggestions? Thanks again. – iliask Apr 04 '12 at 07:24
  • I see. I am supposed to overwrite the class ClassLoaderServiceImpl in org.hibernate.service.classloading.internal and inject my code which includes that null for the parent. Of course I run into other monsters now, such as `Unable to build the default ValidatorFactory` and `Unable to find a default provider` but the ClassCastException error is gone. Did you run into these as well? – iliask Apr 04 '12 at 07:43
  • Ok, got it all to work! I had to include `validation-api.1.0.0.GA.jar`, `slf4j-api-1.6.1.jar`, `slf4j-log4j12-1.6.1.jar` and `hibernate-validator-4.2.0.Final.jar` in order to make it happy and happy it is. :) – iliask Apr 04 '12 at 08:59