gpt4 book ai didi

java - 使用 C3P0 和 Postgresql 的 Hibernate 连接

转载 作者:行者123 更新时间:2023-11-29 06:13:51 25 4
gpt4 key购买 nike

我正在尝试使用 postgresql 和 glassfish 启动并运行应用程序 (jadasite)。 app设计者推荐tomcat和mysql。我真的不能为这个应用程序 atm 使用 tomcat 和 mysql。该应用程序使用 JPA 所以 postgresql 应该没问题。设计者确实提到 postgresql/许多其他数据库应该可以工作。

所以这是我使用以下两页作为引用所做的:

Hibernate Docs

Jadasite forums

jada.properties

log4j.directory=/tmp
hibernate.connection.password=password
working.directory=/tmp
encryption.key=fVOew3eAhr+hdZ9eQLeEtw\=\=
hibernate.connection.url=jdbc\:postgresql:dev-rdbms.example.com:5432/jada"/>
hibernate.connection.driver_class=org.postgresql.drivers

persistence.xml(parital)

<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.username" value="jada"/>
<property name="hibernate.connection.password" value="password"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://dev-rdbms.example.com:5432/jada>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.current_session_context_class" value="thread"/>
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/

然后我使用 mysql2psql 制作一个 postgresql 兼容的数据库转储,加载所有数据并创建具有适当权限和访问权限的适当用户。(通过来自服务器 glassfish 运行的 psql 进行测试)

所以在进行更改后,我将最新的 postgresql jdbc 4 驱动程序放入应用程序 WEB-INF/lib 目录中。制作了一个新的 war 文件并将其部署到我的 glassfish v3.01 服务器。

我收到以下错误。在我看来,C3P0 找不到 JDBC 驱动程序(位于应用程序 WEB-INF/lib 目录和 glassfish 域 lib 目录中)

[#|2011-04-28T11:34:58.508-0500|SEVERE|glassfish3.0.1|

javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=11;_ThreadName=FelixStartLevel;|WebModule[/jada]JadaSite: Unable to initialize JPA connection
javax.persistence.PersistenceException: [PersistenceUnit: jadaSite] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:78)
at com.jada.jpa.connection.JpaConnection.init(JpaConnection.java:79)
at com.jada.system.Initializer.init(Initializer.java:162)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1428)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1230)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5007)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5280)
at com.sun.enterprise.web.WebModule.start(WebModule.java:499)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:928)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:912)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:694)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1947)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1619)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:90)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:126)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:241)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:236)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:339)
at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:362)
at com.sun.enterprise.v3.server.ApplicationLoaderService.postConstruct(ApplicationLoaderService.java:185)
at com.sun.hk2.component.AbstractWombImpl.inject(AbstractWombImpl.java:174)
at com.sun.hk2.component.ConstructorWomb$1.run(ConstructorWomb.java:87)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.hk2.component.ConstructorWomb.initialize(ConstructorWomb.java:84)
at com.sun.hk2.component.AbstractWombImpl.get(AbstractWombImpl.java:77)
at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:58)
at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java:107)
at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:60)
at com.sun.enterprise.v3.server.AppServerStartup.run(AppServerStartup.java:236)
at com.sun.enterprise.v3.server.AppServerStartup.start(AppServerStartup.java:128)
at com.sun.enterprise.module.bootstrap.Main.launch(Main.java:457)
at com.sun.enterprise.module.bootstrap.Main.launch(Main.java:401)
at org.jvnet.hk2.osgiadapter.HK2Main.start(HK2Main.java:125)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:640)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1700)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1622)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:915)
at org.jvnet.hk2.osgimain.Main.start(Main.java:140)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:640)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1700)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1622)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1077)
at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.hibernate.HibernateException: JDBC Driver class not found:
at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:123)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)
at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
... 45 more
Caused by: java.lang.ClassNotFoundException:
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:118)
... 53 more
|#]

有没有人看到我的连接参数有什么问题,或者知道 C3P0 怎么会缺少这些驱动程序?

编辑

我确实看到了一些看起来像是由 C3P0 未找到驱动程序引起的问题,因此我也尝试将 C3P0 jar 放入 glassfish 库中,但仍然出现相同的错误。这是下面评论中的错误,以更好的方式和更多信息。

[#|2011-04-28T12:37:49.964-0500|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=11;_ThreadName=Thread-1;|2011-04-28 12:37:49,964  INFO [FelixStartLevel] (JCLLoggerAdapter.java:265) - Mapping collection: com.jada.jpa.entity.ShippingType.shippingMethodRegionTypes -> shipping_method_region_type
|#]

[#|2011-04-28T12:37:50.009-0500|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=11;_ThreadName=Thread-1;|2011-04-28 12:37:50,008 INFO [FelixStartLevel] (JCLLoggerAdapter.java:265) - Hibernate Validator not found: ignoring
|#]

[#|2011-04-28T12:37:50.405-0500|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=11;_ThreadName=Thread-1;|2011-04-28 12:37:50,404 INFO [FelixStartLevel] (JCLLoggerAdapter.java:286) - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
|#]

[#|2011-04-28T12:37:50.491-0500|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=11;_ThreadName=Thread-1;|2011-04-28 12:37:50,490 INFO [FelixStartLevel] (JCLLoggerAdapter.java:265) - Initializing connection provider: org.hibernate.connection.C3P0ConnectionProvider
|#]

[#|2011-04-28T12:37:50.504-0500|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=11;_ThreadName=Thread-1;|2011-04-28 12:37:50,504 INFO [FelixStartLevel] (JCLLoggerAdapter.java:265) - C3P0 using driver: at URL:
|#]

[#|2011-04-28T12:37:50.506-0500|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=11;_ThreadName=Thread-1;|2011-04-28 12:37:50,505 INFO [FelixStartLevel] (JCLLoggerAdapter.java:265) - Connection properties: {user=, password=****, autocommit=true, release_mode=auto}
|#]

[#|2011-04-28T12:37:50.507-0500|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=11;_ThreadName=Thread-1;|2011-04-28 12:37:50,506 INFO [FelixStartLevel] (JCLLoggerAdapter.java:265) - autocommit mode: true
|#]

[#|2011-04-28T12:37:50.543-0500|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=11;_ThreadName=Thread-1;|2011-04-28 12:37:50,531 ERROR [FelixStartLevel] (JCLLoggerAdapter.java:535) - JDBC Driver class not found:
java.lang.ClassNotFoundException:
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:118)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)
at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:78)
at com.jada.jpa.connection.JpaConnection.init(JpaConnection.java:79)
at com.jada.system.Initializer.init(Initializer.java:162)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1428)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1230)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5007)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5280)
at com.sun.enterprise.web.WebModule.start(WebModule.java:499)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:928)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:912)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:694)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1947)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1619)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:90)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:126)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:241)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:236)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:339)
at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:362)
at com.sun.enterprise.v3.server.ApplicationLoaderService.postConstruct(ApplicationLoaderService.java:185)
at com.sun.hk2.component.AbstractWombImpl.inject(AbstractWombImpl.java:174)
at com.sun.hk2.component.ConstructorWomb$1.run(ConstructorWomb.java:87)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.hk2.component.ConstructorWomb.initialize(ConstructorWomb.java:84)
at com.sun.hk2.component.AbstractWombImpl.get(AbstractWombImpl.java:77)
at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:58)
at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java:107)
at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:60)
at com.sun.enterprise.v3.server.AppServerStartup.run(AppServerStartup.java:236)
at com.sun.enterprise.v3.server.AppServerStartup.start(AppServerStartup.java:128)
at com.sun.enterprise.module.bootstrap.Main.launch(Main.java:457)
at com.sun.enterprise.module.bootstrap.Main.launch(Main.java:401)
at org.jvnet.hk2.osgiadapter.HK2Main.start(HK2Main.java:125)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:640)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1700)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1622)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:915)
at org.jvnet.hk2.osgimain.Main.start(Main.java:140)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:640)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1700)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1622)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1077)
at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
at java.lang.Thread.run(Thread.java:619)
|#]

最佳答案

这里有两件事看起来很奇怪:

1) ClassNotFoundException 的堆栈跟踪没有提到未找到的类的名称:

Caused by: java.lang.ClassNotFoundException:

这似乎暗示它正在尝试加载一个没有名称的类,否则您会期望看到无法找到的类的名称。

2) 不确定这是否只是一个复制和粘贴错误,但在上面的配置片段中,您缺少这一行的结束引号:

<property name="hibernate.connection.url" 
value="jdbc:postgresql://dev-rdbms.example.com:5432/jada>

这会导致格式错误的 XML。

3) 当你说

Made a new jar file and deployed it to my glassfish v3.01 server.

你的意思是说你制作了一个新的“war”文件,而不是“jar”?您需要确保 postgres jdbc jar 最终位于 glassfish 的类路径中。

关于java - 使用 C3P0 和 Postgresql 的 Hibernate 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5822160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com