Hello Everyone,
I am using Hibernate to connect to my MySql Database using C3p0 connection pooling mechanism from my web application which is deployed in Tomcat.
Eventually, now I need to develop a child application, using the same Database instance.
So I have two application now : say Application A and Application B, and both will be deployed in a Tomcat Server and both has to use the same Database, let say my DB name is EmployeeDB.
I defined Resource parameters separately for both of the application and have done all the settings that are required for the connectivity. Now when I deploy the applications, and try to run them, the first application ( it may be Application A or Application B) loads up properly, but the second application shows error as it could not connect to the Database. Whatever application I load first, it successfully connect to the Database, but second application fails to connect.
I am guessing there must be some locking mechanism, provided by either Hibernate or Tomcat, which is preventing me to do so.
Please help me to overcome this issue as that is my fundamental requirement now (i.e. I have to connect to the same database instance from two different web application).
Thanks is advance.
I am posting the stack trace hereby:
Code:
com.mchange.v2.cfg.BasicMultiPropertiesConfig: Properties object found at resource path [system properties] contains a value that is not a String: 25
Skipping...
com.mchange.v2.cfg.BasicMultiPropertiesConfig: Properties object found at resource path [system properties] contains a value that is not a String: 25
Skipping...
921 [http-8990-4] ERROR org.hibernate.connection.C3P0ConnectionProvider - could not instantiate C3P0 connection pool
java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:394)
at com.mchange.v2.c3p0.DataSources.pooledDataSource(DataSources.java:314)
at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:181)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:79)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:448)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
at com.dok.ztil.studentdb.server.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:17)
at com.dok.ztil.studentdb.server.LoginServletImpl.doPost(LoginServletImpl.java:33)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Hibernate Error:::::Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not instantiate C3P0 connection pool
org.hibernate.HibernateException: Could not instantiate C3P0 connection pool
at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:185)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:79)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:448)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
at com.dok.ztil.studentdb.server.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:17)
at com.dok.ztil.studentdb.server.LoginServletImpl.doPost(LoginServletImpl.java:33)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:394)
at com.mchange.v2.c3p0.DataSources.pooledDataSource(DataSources.java:314)
at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:181)
... 22 more
Here is my Hibernate.Cfg.xml file:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="java:hibernate/SessionFactory">
<property name="hibernate.connection.datasource">java:comp/env/jdbc/EmployeeDB</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.acquire_increment">5</property>
<property name="hibernate.c3p0.idle_test_period">1800</property> <!-- seconds -->
<property name="hibernate.c3p0.timeout">180</property> <!-- seconds -->
<property name="hibernate.c3p0.max_size">100</property>
<property name="hibernate.c3p0.max_statements">500</property>
<property name="hibernate.c3p0.min_size">10</property>
<property name="hibernate.c3p0.acquireRetryAttempts">30</property>
<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
<property name="hibernate.c3p0.preferredTestQuery">SELECT 1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">false</property>
<property name="connection.autocommit">false</property>
<mapping resource="com/dok/ztil/studentdb/data/user/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
Please help..!