11

私のhibernate.cfg.xml

<property name="connection.driver_class">org.postgresql.Driver</property>
        <property name="show_sql">true</property>
        <property name="connection.url">jdbc:postgresql://localhost:5432/pirates</property>
        <property name="connection.username">postgres</property>
        <property name="connection.password">mmm888</property>

        <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="show_sql">false</property>
        <property name="hbm2ddl.auto">update</property>
        <property name="current_session_context_class">thread</property>

        <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> 
        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.max_size">200</property>
        <property name="hibernate.c3p0.timeout">300</property>
        <property name="hibernate.c3p0.max_statements">50</property>
        <property name="hibernate.c3p0.idle_test_period">3000</property>
        <property name="hibernate.generate_statistics">true</property>

私のライブラリ:

hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-4.1.10.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-validator-4.2.0.Final.jar
jbossjta-4.16.4.Final.jar
jboss-logging-3.1.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar
openjdk-6-b14.jar
validation-api-1.0.0.GA.jar
hibernate-c3p0-4.1.10.Final.jar

と私のエラー:

29.04.2013 14:02:43 org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator getConfiguredConnectionProviderName
WARN: HHH000208: org.hibernate.connection.C3P0ConnectionProvider has been deprecated in favor of org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider; that provider will be used instead.
29.04.2013 14:02:43 org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator instantiateExplicitConnectionProvider
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
Failed to create sessionFactory object.org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
29.04.2013 14:02:43 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [request] in context with path [/Pirates] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
    at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138)
    at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:189)
    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)
    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:2277)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2273)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1742)
    at hibernate.Hibernate.initFactory(Hibernate.java:39)
    at hibernate.Hibernate.getFactory(Hibernate.java:23)
    at hibernate.Hibernate.openSession(Hibernate.java:49)
    at action.Action.init(Action.java:96)
    at action.Action.performAction(Action.java:65)
    at servlets.RequestHandlerServlet.service(RequestHandlerServlet.java:39)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
4

2 に答える 2

11

私は同じ問題を抱えていました。私の解決策もあなたに役立つことを願っています:

1: hibernate-c3p0-4.1.10.Final.jar を使用しているため、provider_class は次のようになります。

<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>

エラーの原因: org.hibernate.HibernateException: 接続プロバイダーをインスタンス化できませんでした [org.connection.C3P0ConnectionProvider]

また、c3p0-0.9.1.jar と hibernate-c3p0-4.2.1.Final.jar の両方が含まれていることを確認してください (同じフォルダー "\hibernate-release-4.2.1.Final\lib\optional\c3p0 にある必要があります)。 \" )

ここで最新のHibernateリリース(4.2.1)をダウンロードしましたhttp://planet.jboss.org/post/hibernate_orm_4_2_1_final_and_4_1_12_final_released

eclipse のダウンロード リンクには 3.6.0 の最終バージョンしかないため (JBoss Hibernate - http://download.jboss.org/jbosstools/updates/stable / )

于 2013-05-05T15:26:31.847 に答える
5

c3p0

hibernate ディストリビューションの lib ディレクトリにある上記のライブラリ jar ファイルを追加します。

于 2014-11-06T08:06:25.460 に答える