当前位置: 首页 > 知识库问答 >
问题:

无法使用C3P0在Karaf中创建JPA连接池

邓越泽
2023-03-14

无法使用C3P0创建Hibernate-JPA连接池。面对以下错误日志

com.employee.mgmt.sys.db.provider.EmployeeDBProvider(30)] The activate method has thrown an exception org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:261)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:225)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
    at org.hibernate.osgi.OsgiPersistenceProvider.createContainerEntityManagerFactory(OsgiPersistenceProvider.java:112)
    at org.apache.aries.jpa.container.impl.AriesEntityManagerFactoryBuilder.createEntityManagerFactory(AriesEntityManagerFactoryBuilder.java:55)
    at com.employee.mgmt.sys.db.provider.EmployeeDBProvider.createEntityManagerFactoryObjects(EmployeeDBProvider.java:63)
    at com.employee.mgmt.sys.db.provider.EmployeeDBProvider.activate(EmployeeDBProvider.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

[:1.8.0_121] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_121] 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_121]
    at org.apache.felix.scr.impl.inject.BaseMethod.invokeMethod(BaseMethod.java:224)[73:org.apache.felix.scr:2.0.6]
    at org.apache.felix.scr.impl.inject.BaseMethod.access$500(BaseMethod.java:39)[73:org.apache.felix.scr:2.0.6]
    at org.apache.felix.scr.impl.inject.BaseMethod$Resolved.invoke(BaseMethod.java:617)[73:org.apache.felix.scr:2.0.6]
    at org.apache.felix.scr.impl.inject.BaseMethod.invoke(BaseMethod.java:501)[73:org.apache.felix.scr:2.0.6]
    at org.apache.felix.scr.impl.inject.ActivateMethod.invoke(ActivateMethod.java:302)[73:org.apache.felix.scr:2.0.6]
    at org.apache.felix.scr.impl.inject.ActivateMethod.invoke(ActivateMethod.java:294)[73:org.apache.felix.scr:2.0.6] 
    at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:297)[73:org.apache.felix.scr:2.0.6] 
    at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:108)[73:org.apache.felix.scr:2.0.6] 
    at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:906)[73:org.apache.felix.scr:2.0.6] 
    at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:879)[73:org.apache.felix.scr:2.0.6] 
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:748)[73:org.apache.felix.scr:2.0.6] 
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.enableInternal(AbstractComponentManager.java:674)[73:org.apache.felix.scr:2.0.6] 
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:429)[73:org.apache.felix.scr:2.0.6] 
    at org.apache.felix.scr.impl.manager.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:657)[73:org.apache.felix.scr:2.0.6] 
    at org.apache.felix.scr.impl.BundleComponentActivator.initialEnable(BundleComponentActivator.java:341)[73:org.apache.felix.scr:2.0.6] 
    at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:403)[73:org.apache.felix.scr:2.0.6] 
    at org.apache.felix.scr.impl.Activator.access$200(Activator.java:54)[73:org.apache.felix.scr:2.0.6] 
    at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:278)[73:org.apache.felix.scr:2.0.6] 
    at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259)[73:org.apache.felix.scr:2.0.6] 
    at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232)[73:org.apache.felix.scr:2.0.6] 
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:482)[org.osgi.core-6.0.0.jar:] 
    at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:415)[org.osgi.core-6.0.0.jar:] 
    at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232)[org.osgi.core-6.0.0.jar:] 
    at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:444)[org.osgi.core-6.0.0.jar:] 
    at org.apache.felix.framework.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:915)[org.apache.felix.framework-5.6.1.jar:] 
    at org.apache.felix.framework.EventDispatcher.fireEventImmediately(EventDispatcher.java:834)[org.apache.felix.framework-5.6.1.jar:] 
    at org.apache.felix.framework.EventDispatcher.fireBundleEvent(EventDispatcher.java:516)[org.apache.felix.framework-5.6.1.jar:] 
    at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4541)[org.apache.felix.framework-5.6.1.jar:] 
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2172)[org.apache.felix.framework-5.6.1.jar:] 
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)[org.apache.felix.framework-5.6.1.jar:] 
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:984)[org.apache.felix.framework-5.6.1.jar:] 
    at org.apache.karaf.bundle.command.Install.execute(Install.java:96)[23:org.apache.karaf.bundle.core:4.0.8] 
    at org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:83)[43:org.apache.karaf.shell.core:4.0.8] 
    at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:67)[43:org.apache.karaf.shell.core:4.0.8] 
    at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:87)[43:org.apache.karaf.shell.core:4.0.8] 
    at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)[43:org.apache.karaf.shell.core:4.0.8] 
    at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)[43:org.apache.karaf.shell.core:4.0.8] 
    at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[43:org.apache.karaf.shell.core:4.0.8] 
    at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)[43:org.apache.karaf.shell.core:4.0.8] 
    at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)[43:org.apache.karaf.shell.core:4.0.8] 
    at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)[43:org.apache.karaf.shell.core:4.0.8] 
    at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:274)[43:org.apache.karaf.shell.core:4.0.8] 
    at java.lang.Thread.run(Thread.java:745)

[:1.8.0_121] Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.hibernate.c3p0.internal.C3P0ConnectionProvider] 
    at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:197)
    at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:120) 
    at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:55) 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:105) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:251) ... 64 more 

Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.c3p0.internal.C3P0ConnectionProvider] as strategy [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider] 
    at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:128) 
    at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:194) ... 68 more

请求请提供一个解决方案如何创建连接池使用JPA在KARAF。

共有1个答案

冯枫涟
2023-03-14

在仔细检查了您提供的错误stacktrace之后,我认为问题与您使用的hibernate.c3po.*属性有关。

您可能需要参考以下文档:

C3P0ConnectionProvider

<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
    <default-config>
    <property name="initialPoolSize">5</property>
    <property name="minPoolSize">5</property>
    <property name="maxPoolSize">10</property>
    <property name="checkoutTimeout">3000</property>
    <property name="maxStatementsPerConnection">30</property>

    <property name="preferredTestQuery">SELECT 1 FROM DUAL</property>
    <property name="testConnectionOnCheckin">true</property>
    <property name="testConnectionOnCheckout">false</property>
    <property name="idleConnectionTestPeriod">300</property>
    </default-config>
</c3p0-config>
 类似资料:
  • 我的应用程序有两个quartz作业同时从Oracle DB读取两个不同的表。我正在尝试使用c3p0与Hibernate和Oracle从池中获取连接。Tomcat7启动时,C3P0似乎已初始化: 2021-02-15 18:47:26,271[INFO]HibernateEntityManager 3.2.1.GA 2021-02-15 18:47:26,290[INFO]Hibernate注释3.

  • 我试图在JSPlumb中创建两个endpoint之间的直线连接。当我尝试连接到endpoint时,将拖动源点,而不是创建直线连接。 这里是小提琴:http://jsfiddle.net/dutchman71/aMksZ/2/ 谢谢你的帮助。

  • 我正在尝试在分布式模式下运行Kafka辅助角色。与独立模式不同,我们在分布式模式下启动辅助角色时无法传递连接器属性文件。在分布式模式下,辅助角色是单独启动的,我们使用REST API部署和管理这些辅助角色上的连接器 参考链接 - https://docs.confluent.io/current/connect/managing/configuring.html#connect-managing-

  • 使用SSL连接到Postgres时引发异常。 原因:javax.net.ssl.SSLException:收到致命警报:在sun . security . SSL . alerts . getsslexception(alerts . Java:208)在sun . security . SSL . alerts . getsslexception(alerts . Java:154)在sun .

  • 我在应用程序中看到一个非常奇怪的行为。 我的应用程序设置:Spring Hibernate C3p0 应用程序保持运行良好,当突然我开始看到这些错误的日志和系统完全停止处理任何数据库特定的请求。 为什么C3p0需要在这个特殊的时间创建一个新的连接池,在这些异常之前,应用程序100%工作正常,响应良好 有什么线索吗? =========================================

  • 我的应用程序使用的是Hibernate 4.1.7和c3p0 0.9.1。 我已经将应用程序的hibernate.cfg.xml文件中的c3p0.max_size属性设置为50,但是创建的JDBC连接数已经超过了这个值。而且,不活动/空闲连接不会被删除,这也是我在Hibernate配置中指定的。以下是我配置的一个片段: 我在代码中的finally块中显式关闭会话和会话工厂。下面是我用来创建Sess