Eclipse中的Hibernate工具出错无法创建请求的服务[org.hibernate.service.jdbc.connections.spi.ConnectionProvider]

时间:2013-09-14 06:32:29

标签: java eclipse hibernate c3p0

hibernate.cfg.xml中

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.password">cisadm</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:CCB240</property>
        <property name="hibernate.connection.username">cisadm</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>    
    </session-factory>
</hibernate-configuration>

hibernate.properties

hibernate.connection.driver_class = oracle.jdbc.driver.OracleDriver 

hibernate.connection.url = jdbc:oracle:thin:@localhost:1521:CCB240

hibernate.connection.username = cisadm
hibernate.connection.password = ENC(YoYU3xkTjrrX1hIbldx9DhkGadCBjvliVNh/i4CWQvg=)
hibernate.dialect = org.hibernate.dialect.Oracle10gDialect
hibernate.show_sql = false
hibernate.max_fetch_depth = 2
hibernate.transaction.factory_class = org.hibernate.transaction.JDBCTransactionFactory

hibernate.jdbc.fetch_size = 100
hibernate.jdbc.batch_size = 30   
hibernate.query.factory_class=org.hibernate.hql.classic.ClassicQueryTranslatorFactory
hibernate.cache.use_second_level_cache = false
hibernate.query.substitutions = true 'Y', false 'N'    

hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
hibernate.c3p0.acquire_increment=1
hibernate.c3p0.idle_test_period=180
hibernate.c3p0.max_size=60
hibernate.c3p0.max_statements=0
hibernate.c3p0.min_size=10

我的Hibernate工具配置在下面的链接中。

Tool Configuration

但是当我在HQL编辑器中运行hql时,我得到以下错误

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:193)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:156)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:139)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:208)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:85)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:165)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:139)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2259)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2255)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
at org.jboss.tools.hibernate4_0.HibernateExtension4_0$3.execute(HibernateExtension4_0.java:118)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
at org.jboss.tools.hibernate4_0.HibernateExtension4_0.execute(HibernateExtension4_0.java:211)
at org.jboss.tools.hibernate4_0.HibernateExtension4_0.buildSessionFactory(HibernateExtension4_0.java:110)
at org.hibernate.console.ConsoleConfiguration.buildSessionFactory(ConsoleConfiguration.java:283)
at org.hibernate.eclipse.console.actions.ExecuteQueryAction.execute(ExecuteQueryAction.java:82)
at org.hibernate.eclipse.console.actions.ExecuteQueryAction.run(ExecuteQueryAction.java:56)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at org.hibernate.eclipse.console.actions.ExecuteQueryAction.runWithEvent(ExecuteQueryAction.java:60)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:452)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
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.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
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:190)
at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:112)
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:183)
... 48 more

我正在添加hibernate-c3p0-4.1.0.Final.jar,在下拉列表中我选择Hibernate版本为4.我做错了什么?

我正在使用:

  • JBoss Hibernate Tool 3.3
  • Eclipse Indigo

4 个答案:

答案 0 :(得分:1)

我在这里写的评论很难说清楚。在课堂上

  org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator

在return语句中的下面的方法中放置一个断点。它会导致运行时抛出异常。在调试模式下,我们将了解正在发生的事情,并希望完成此回复:

private ConnectionProvider More ...instantiateExplicitConnectionProvider(
        String providerClassName,
        ClassLoaderService classLoaderService) {
    try {
        LOG.instantiatingExplicitConnectionProvider( providerClassName );
        return (ConnectionProvider) classLoaderService.classForName( providerClassName ).newInstance();
    }
    catch ( Exception e ) {
        throw new HibernateException( "Could not instantiate connection provider [" + providerClassName + "]", e );
    }
}

答案 1 :(得分:1)

在类路径中添加 mysql驱动程序jar。

  

MySQL的连接器的Java-5.1.21-bin.jar

答案 2 :(得分:0)

问题是我们的hibernate配置文件。使用此代码更改配置。

<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@<host>:<port>:<sid></property>
<property name="connection.username">username</property>
<property name="connection.password">password</property>

<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">false</property>

答案 3 :(得分:0)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM "http://hibernate.sourceforge.net/hibernate-configuration-5.0.dtd">

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql//localhost/db_catalogue_glsid</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password"></property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.hbm2ddl.auto">create</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <mapping class="metier.entite.Produit"/>
    </session-factory>
</hibernate-configuration>