I wrote a server-side application that powers a website and multiple mobile clients. I used Hibernate for data access. I later discovered that the app fails after a day! When I checked around online, I found out that its a well know issue with MySQL terminating a "stale" connection after 8 hours. In order to avoid this, I found many suggestions like including ?autoReconnect=true, using c3P0, etc.
Since autoReconnect is officially discouraged (especially in production environment) and also because it didn't have any effect when I applied it, I decided to go for c3p0. Unfortunately, after introducing the c3p0 configuration in my hibernate.cfg.xml file, the application starts throwing a NullPointerException somewhere in my code where I called dbSession.close()
This means that the HibernateUtil.getSessionFactory() actually returns null. I have added the required jars (c3p0-0.9.2-pre2.jar, hibernate-core-3.3.1.GA.jar, hibernate-c3p0-3.3.2.GA.jar, mchange-commons-java-0.2.1.jar and c3p0-oracle-thin-extras-0.9.2-pre2.jar) even though I don't think its all of them that are required.
I've gone through many of the pages that talked about this issue but I'm still not able to set it up properly. Kindly help me with a "beginner-friendly" easy-to-implement, step-by-step procedure for setting up c3p0 with Hibernate. I'm using Hibernate 3.3.6 on JDK 1.6, MySQL 5.5 and I'm developing in Netbeans 7.0.
Here is my hibernate.cfg.xml
<?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>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/religion_app</property>
<property name="hibernate.connection.username">*****</property>
<property name="hibernate.connection.password">*****</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="connection.autoReconnect">true</property>
<property name="connection.autoReconnectForPools">true</property>
<property name="connection.is-connection-validation-required">true</property>
<!-- configuration pool via c3p0-->
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">120</property> <!-- seconds -->
<property name="c3p0.max_size">100</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">10</property>
<property name="c3p0.timeout">180</property> <!-- seconds -->
<property name="c3p0.preferredTestQuery">select 1;</property>
<!--Mappings go here-->
</session-factory>
</hibernate-configuration>
Here is what I got after adding c3p0 (without slf4j):
May 23, 2012 2:42:14 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet LoginChurch threw exception
java.lang.NullPointerException
at com.pacesolutions.religionapp.services.LoginChurch.processRequest(LoginChurch.java:109)
at com.pacesolutions.religionapp.services.LoginChurch.doPost(LoginChurch.java:138)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
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:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
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:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
at java.lang.Thread.run(Thread.java:722)
May 23, 2012 2:45:13 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet LoginChurch threw exception
java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)
at org.hibernate.connection.C3P0ConnectionProvider.<clinit>(C3P0ConnectionProvider.java:52)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:73)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
at com.pacesolutions.religionapp.HibernateUtil.<clinit>(HibernateUtil.java:23)
at com.pacesolutions.religionapp.services.LoginChurch.processRequest(LoginChurch.java:68)
at com.pacesolutions.religionapp.services.LoginChurch.doPost(LoginChurch.java:143)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
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:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
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:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
at java.lang.Thread.run(Thread.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.
Most of my Hibernate configuration files where generated by Netbeans. I had the database on ground then I used the Hibernate wizards in Netbeans to generate the configuration files, entity classes and mapping files from it. These were working correctly before I introduced c3p0 (but they fail after 8 hours).
I use Mecurial with my project and reverting the whole project back to a time prior to when I introduced c3p0, it works again (for 8 hours). Even hand-deleting all the c3p0 configurations in hibernate.cfg.xml makes the app work again. What could I be doing wrong?
The jars required for C3P0 configuration are c3p0-0.9.2-pre2.jar & mchange-commons-java-0.2.1.jar. Also, additionally you need to put c3p0.properties in classpath.
Below are the properties, which should be configured while using C3P0 with Hibernate.
hibernate.cfg.xml
<property name="connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">100</property>
<property name="hibernate.c3p0.max_size">100</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.min_size">10</property>
<property name="hibernate.c3p0.timeout">180</property>
c3p0.properties
You can validate connection on each checkout c3p0.testConnectionOnCheckout=true, but this is expensive operation.
Else, you can retry to establish connection periodically.
c3p0.acquireRetryAttempts = 4
c3p0.acquireRetryDelay = 5000
This will retry 4 times with a delay of 5 seconds between each consecutive attempt.
c3p0 has no dependency on SLF4J. If adding that library to your classpath fixed your issue, that is interesting, but not so easy to explain.
A stack trace of the original NPE tomcat logged when you had problems would be helpful. (I'm c3p0's developer.)
Note that c3p0.properties needs to be at the top level of the CLASSPATH of your app, which may not be where other config files are located. c3p0.properties is loaded as a ClassLoader resource.
The bug can be fixed using commercial pooling libraries as suggested above. I used c3p0 exactly as suggested by #NayanWadekar.
Please note that c3p0 is dependent on SLF4J. So after including the c3p0 jars in your classpath, you also have to add SLF4J jars in your classpath. The trick about this thing is that, if those SLF4J jars are not present, the compiler still won't complain, you only get errors after deploying the app.
Also, if you are using Netbeans, avoid creating an SLF4J library from all the jars bundled together here at slf4.org. The reason being that some of the jars are not meant to be used together in the same project. Just use the following two jars alone from the library: slf4j-api-1.6.4.jar and slf4j-jdk14-1.6.4.jar. You can visit www.slf4j.org for details.
Related
I am testing payara 5 with jdk 17.
But I have problems with the connection pool.
<jdbc-connection-pool max-pool-size="100" datasource-classname="oracle.jdbc.pool.OracleDataSource" steady-pool-size="1" validation-table-name="dual" name="oracle_thin_emp" is-connection-validation-required="true" res-type="javax.sql.DataSource">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="URL" value="jdbc:oracle:thin:#192.168.50.19:1521:TD"></property>
<property name="serverName" value="192.168.50.19"></property>
<property name="User" value="EMP"></property>
<property name="Password" value="EMP"></property>
<property name="PortNumber" value="1521"></property>
<property name="databaseName" value="TD"></property>
</jdbc-connection-pool>
When I start payara 5 with jdk 8 the connection pool works correctly but when I start the web server with jdk 17 and ping from the admin console I get the following error:
Ping Connection Pool failed for oracle_thin_emp. Class name is wrong or classpath is not set for : oracle.jdbc.pool.OracleDataSource Please check the server.log for more details.
Log:
[Payara 5.2022.2] [SEVERE] [] [javax.enterprise.resource.resourceadapter.com.sun.gjc.util] [tid: _ThreadID=163 _ThreadName=admin-thread-pool::admin-listener(4)] [timeMillis: 1657657513953] [levelValue: 1000] [[
RAR5099 : Wrong class name or classpath for Datasource Object
java.lang.ClassNotFoundException: oracle.jdbc.pool.OracleDataSource
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
at com.sun.enterprise.loader.CurrentBeforeParentClassLoader.loadClass(CurrentBeforeParentClassLoader.java:83)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
Details:
JDK: oracle jdk-17.0.3.1
Server: payara 5.2022.2
Driver: payara5\glassfish\domains\domain1\lib\ext\ojdbc7-12.1.0.2.jar
Place the driver in one directory above, <payara-home>/glassfish/domains/<domain>/lib.
The reason seems to be that the extension mechanism (system property java.ext.dirs) has been removed from Java 9.
Also, the PayaraServer5.192 Release Notes states that <payara-home>/glassfish/domains/<domain>/lib/ext are no longer placed in the classpath.
PayaraServer officially supports Java 11 in addition to Java 8 since 5.192, but it seems to be a corresponding response.
I am aware this issue comes up when no proper jdbc driver jar is configured in the build path, I have tried adding a few jdbc jars for postgres, yet I face the issue. Please find the below jars I tried.
Using
postgres : 1.16.1
Eclipse Version: Indigo Service Release 2
Java version : 8
Jars I tried
postgresql-9.4.1208.jre6
postgresql-connector-jdbc4.jar
postgresql-jdbc.jar
postgresql-9.3-1103.jdbc3
postgresql-9.2-1003-jdbc4-sources.jar
pg73jdbc3
jdbc7.1-1.1
Reading other posts on stack overflow, I even tried setting the system environmental variables as below..
User Variables - Admin - classpath
C:\Program Files\PostgreSQL\9.2\lib
System Variable - path
C:\Program Files\PostgreSQL\9.2\bin
Not sure if this is required
Database details setup in my .properties file
jdbc.driverClassName=org.postgresql.Driver
jdbc.url=postgresql://localhost:5432/postgres
jdbc.username=admin
jdbc.password=admin
Using spring framework based application
Logs :
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: No suitable driver found for postgresql://localhost:5432/postgres
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:240)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy8.getCollegeDetails(Unknown Source)
at com.cts.bo.HESBO.registerCourse(HESBO.java:42)
at com.cts.facade.HESFacade.registerCourse(HESFacade.java:34)
at com.cts.manager.HESManager.registerCourse(HESManager.java:34)
at com.cts.presentation.Tester.registerCourse(Tester.java:66)
at com.cts.presentation.Tester.main(Tester.java:159)
Caused by: java.sql.SQLException: No suitable driver found for postgresql://localhost:5432/postgres
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:149)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:202)
... 11 more
Please guide as for what needs to be done.Thanks
You don't add url while filling the database details for postgresql. You instead do the following.
<bean id="dataSource" class="org.postgresql.xa.PGXADataSource">
<property name="user" value="${username}" />
<property name="password" value="${password}" />
<property name="portNumber" value ="${portNumber}" />
<property name="databaseName" value="${databaseName}" />
<property name="serverName" value="${serverName}" />
</bean>
in your application context and
username=yourusername
password=******
portNumber=5432
databaseName=yourdb
serverName=localhost
in your property file.Later ofcourse you need to utilize the datasource bean. Look at the following, https://jdbc.postgresql.org/documentation/publicapi/org/postgresql/xa/PGXADataSource.html.
I'm currently building a little web-based tool using hibernate. I testrun the site in eclipse using a Tomcat v7.0 Server. My Database is using MySQL version 5.6 on Linux.
Now, everytime I run the program, starting my index.xhtml on the server, i get an outrageous error Message that looks like this:
ERROR: HHH000300: Could not complete schema validation
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'system_sequences' in information_schema
at sun.reflect.GeneratedConstructorAccessor48.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
at com.mysql.jdbc.Util.getInstance(Util.java:360)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:978)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2526)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2484)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1446)
at org.hibernate.tool.hbm2ddl.DatabaseMetadata.initSequences(DatabaseMetadata.java:178)
at org.hibernate.tool.hbm2ddl.DatabaseMetadata.<init>(DatabaseMetadata.java:92)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:168)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:525)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)
at com.ubs.tbt.database.KurseDAO.getModule(KurseDAO.java:139)
at com.ubs.tbt.database.Klasse.module(Klasse.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:165)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:84)
at org.apache.el.parser.AstValue.getValue(AstValue.java:159)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at com.sun.faces.facelets.component.UIRepeat.getValue(UIRepeat.java:274)
at com.sun.faces.facelets.component.UIRepeat.getDataModel(UIRepeat.java:250)
at com.sun.faces.facelets.component.UIRepeat.setIndex(UIRepeat.java:444)
at com.sun.faces.facelets.component.UIRepeat.doVisitChildren(UIRepeat.java:679)
at com.sun.faces.facelets.component.UIRepeat.visitTree(UIRepeat.java:637)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIForm.visitTree(UIForm.java:371)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at org.primefaces.component.api.UITabPanel.visitTree(UITabPanel.java:920)
at com.sun.faces.facelets.component.UIRepeat.visitTree(UIRepeat.java:643)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at com.sun.faces.application.view.FaceletPartialStateManagementStrategy.saveView(FaceletPartialStateManagementStrategy.java:472)
at com.sun.faces.application.StateManagerImpl.saveView(StateManagerImpl.java:89)
at javax.faces.application.StateManager.getViewState(StateManager.java:593)
at com.sun.faces.context.PartialViewContextImpl.renderState(PartialViewContextImpl.java:454)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:322)
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1004)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:417)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
My hibernate.cfg
<?xml version='1.0'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://192.168.1.34:3306/BeurteilungsDB</property>
<property name="connection.username">admin</property>
<property name="connection.password">po2015</property>
<!-- Zusaetzliche Hibernate-Properties -->
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.hbm2ddl.auto">validate</property>
<!-- Definition der gemappten Klassen -->
<!-- <mapping class="ch.fg.bibliothek.Verlag" />-->
<mapping class="com.ubs.tbt.database.Eventbewertung" />
<mapping class="com.ubs.tbt.database.Modulbewertung" />
<mapping class="com.ubs.tbt.database.Teilnehmer" />
<mapping class="com.ubs.tbt.database.Klasse" />
<mapping class="com.ubs.tbt.database.Firma" />
<mapping class="com.ubs.tbt.database.Kursleiter" />
<mapping class="com.ubs.tbt.database.Module" />
<mapping class="com.ubs.tbt.database.Kurse" />
</session-factory>
</hibernate-configuration>
The program itself runs normally and works the way its supposed to, but I'm having a hard time validating the rest of my console outputs, when this message is printed every second Line in the console.
Something worth mentioning is that I started receiving this message after adding the keyword validate at <property name="hibernate.hbm2ddl.auto">validate</property>.
Where is this table supposed to be and most important, how do I get rid of this Message?
First you need to understand the hibernate mapping to ddl, hbm2ddl.auto settings.
From the docs hibernate.hbm2ddl.auto:
Automatically validates or exports schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly.
e.g. validate | update | create | create-drop
validate: validate the schema, makes no changes to the database.
update: update the schema.
create: creates the schema, destroying previous data.
create-drop: drop the schema at the end of the session.
Your config fails to validate the schema as it can not find the information_schema.system_sequences. I think it is because the dialect you have chosen.
try to replace the org.hibernate.dialect.HSQLDialect with org.hibernate.dialect.MySQLDialect
Look at doc url to pick the right dialect, and verify the rest of the config.
MySQL hibernate dialects:
MySQL org.hibernate.dialect.MySQLDialect
MySQL with InnoDB org.hibernate.dialect.MySQLInnoDBDialect
MySQL with MyISAM org.hibernate.dialect.MySQLMyISAMDialect
The information_schema is MySQL own information database. It contains all information about all the other (your own) databases that are maintained in its database server.
Change org.hibernate.dialect.HSQLDialect to org.hibernate.dialect.MySQLDialect.
In your application.properties you should have spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect It worked with MySQL Connector 8.
I am trying to get a basic Seam 3 webapplication to work and use the jboss-javaee6-webapp to achieve this goal. Using the manual at http://seamframework.org/Documentation/CDIQuickstartForMavenUsers.
However, I am running into some problems which I haven't been able to solve for days. I have basically no experience in JavaEE so the solution is probably really easy.
What I've done? I've simply generated a new maven project based on the supplied archetype and didn't change anything about it. I've installed Eclipse Helios including JBoss Tools and downloaded JBoss 6.0.0 and got Eclipse to deploy the application to the server succesfully.
While deploying, an exception occurs in the example code. To be specific the following exceptions occurs:
09:29:20,712 WARN [seam3-example] Seed data import failed.: java.lang.NullPointerException
at org.jboss.weld.integration.persistence.JBossJpaServices.resolvePersistenceContext(JBossJpaServices.java:59) [:6.0.0.Final]
at org.jboss.weld.util.Beans.injectEEFields(Beans.java:781) [:6.0.0.Final]
at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget$1$1.proceed(ManagedBean.java:181) [:6.0.0.Final]
at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:54) [:6.0.0.Final]
at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget$1.work(ManagedBean.java:176) [:6.0.0.Final]
at org.jboss.weld.bean.ManagedBean$FixInjectionPoint.run(ManagedBean.java:142) [:6.0.0.Final]
at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget.inject(ManagedBean.java:170) [:6.0.0.Final]
at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:339) [:6.0.0.Final]
at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:67) [:6.0.0.Final]
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:669) [:6.0.0.Final]
at org.jboss.weld.bean.AbstractReceiverBean.getReceiver(AbstractReceiverBean.java:84) [:6.0.0.Final]
at org.jboss.weld.bean.ProducerField$1.produce(ProducerField.java:134) [:6.0.0.Final]
at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:361) [:6.0.0.Final]
at org.jboss.weld.bean.builtin.ee.EEResourceProducerField.createUnderlying(EEResourceProducerField.java:170) [:6.0.0.Final]
at org.jboss.weld.bean.builtin.ee.EEResourceProducerField.access$000(EEResourceProducerField.java:54) [:6.0.0.Final]
at org.jboss.weld.bean.builtin.ee.EEResourceProducerField$EEResourceCallable.call(EEResourceProducerField.java:80) [:6.0.0.Final]
at org.jboss.weld.bean.builtin.CallableMethodHandler.invoke(CallableMethodHandler.java:50) [:6.0.0.Final]
at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:62) [:6.0.0.Final]
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:125) [:6.0.0.Final]
at org.jboss.weldx.persistence.org$jboss$weld$bean-jboss$classloader:id="vfs:$$$Users$sander$Workspaces$eclipse$web-dev-32$$metadata$$plugins$org$jboss$ide$eclipse$as$core$JBoss_6$0_Runtime_Server1306911969901$deploy$seam3-example$war"-ProducerField-nl$jdi$examples$data$MemberRepositoryProducer$em_$$_WeldProxy.persist(org$jboss$weld$bean-jboss$classloader:id="vfs:$$$Users$sander$Workspaces$eclipse$web-dev-32$$metadata$$plugins$org$jboss$ide$eclipse$as$core$JBoss_6$0_Runtime_Server1306911969901$deploy$seam3-example$war"-ProducerField-nl$jdi$examples$data$MemberRepositoryProducer$em_$$_WeldProxy.java)
at nl.jdi.examples.data.SeedDataImporter.importData(SeedDataImporter.java:51) [:]
...
I've searched for a solution for this exact exception but I could barely find anything about it. This probably means that I've overlooked something very simple. So I've analysed the exception and found the following:
The exception message is from the example code (SeedDataImporter.java:61)
The exception itself (NullPointer) is thrown somewhere in the weld code
The problem seems to be purely persistence related (it can't find the PersistenceContext?)
Since the problem is persistence related, I've tried to change the persistence.xml however this didn't pay out. I think the problem is within the JDNI/Persistence.xml/Server config domain, however I can't be sure.
Can anybody point me in the right direction?
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="primary">
<jta-data-source>jdbc/__default</jta-data-source>
<properties>
<!-- Properties for Hibernate (default provider for JBoss AS) -->
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="false" />
<!-- Properties for EclipseLink (default provider for GlassFish) -->
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.logging.level" value="FINE" />
</properties>
</persistence-unit>
Edit:
When I try to deploy the unchanged application to GlassFish 3.1 within Eclipse I get the following error:
cannot Deploy seam3-example
Deployment Error for module: seam3-example: Error occurred during deployment: Exception while loading the app : javax.ejb.CreateException: Initialization failed for Singleton SeedDataImporter. Please see server.log for more details.
Cannot create tables for application seam3-example. The expected DDL file seam3-example_primary_createDDL.jdbc is not available.
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.
I think it is a persistance.xml problem because you have:
<jta-data-source>jdbc/__default</jta-data-source>
and this is default for Glassfish AS
Try this:
<jta-data-source>java:/DefaultDS</jta-data-source>
This is default for JBoss
Do you run JBoss AS in default domain?
If you check the persistence.xml file generated by the archetype, you'll see this comment:
<!-- A matching data source is added to JBoss AS by deploying the project file default-ds.xml -->
<jta-data-source>jdbc/__default</jta-data-source>
Inside resources-jbossas there's a default-ds.xml file that you should deploy to JBoss in order to be able to use the app without any code changes.
At least on the command line I can start the example doing this:
Download and install the latest jboss 6 to
mvn archetype:generate -DarchetypeArtifactId=jboss-javaee6-webapp -DarchetypeGroupId=org.jboss.weld.archetypes -DarchetypeVersion=1.0.1.CR1 -DarchetypeRepository=central -DgroupId=com.example -DartifactId=jee-example -Dversion=0.0.1-SNAPSHOT
cd jee-example
mvn clean package jboss:hard-deploy -Djboss.home=<jboss-6.0.0.Final>
start the jboss with <jboss-6.0.0.Final>/bin/run.sh (run.bat on Windws)
open http://localhost:8080/jee-example/
For more details have a look at the readme.html that is created by the archtype in the same folder as the pom.xml
To work in eclipse you should install
eclipse for Java EE Developers
m2eclipse from this update site
m2eclipse wtp extension from the m2eclipse-extra update site documentation
I did not try the eclipse part for the archetype...
Hi iv been struggling with this error for some time and really cant figure out why its occurring , i have a web application that uses springs simpleJdbctemplate to access a database i can use this locally and it has been tested but when i deploy the application jersey has some problems running the queries on the server this is the stacktrace from the tomcat logs
10-Jan-2011 21:15:28 com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NullPointerException
at example.jersey.spring.dao.testDAO.getUsers(testDAO.java:20)
at example.jersey.spring.MyResource.getIt(MyResource.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:168)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:74)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1357)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1289)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1239)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1229)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:497)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:684)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
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:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
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:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
This is my resource
#GET
#Produces("text/plain")
public String getIt() {
return "the number of users are " +db.getUsers();
}
TestDAO.java
SimpleJdbcTemplate simpleJdbcTemplate ;
public void setDataSource(final DataSource dataSource) {
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
}
applicationContext.xml
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</bean>
<bean id="testDAO" class="com.example.testDAOimpl">
<property name="dataSource" ref="dataSource"/>
</bean>
running locally in eclipse the db.getusers returns - the correct value of 1 so i cant understand why it doesnt work when deployed
Any help greatly appreciated
(Seems to be no real difference from the local set up and the server set up ) if anyone has encountered this anyhelp is much appreciated)
Thanks
Chris
Not sure if this is your problem. But I was facing a similar issue. And what ended up happening is I was missing the MimeMultipart.class on my class path in my server code. Jersey was unable to find the class, and therefore unable to map the server request properly. Strangest thing was I never saw any kind of error message on the server side indicating a class not found.
Assuming you use a bean factory, do something like this to get it from spring:
BeanFactoryLocator beanFactoryLocator = SingletonBeanFactoryLocator.getInstance();
BeanFactoryReference beanFactoryReference = beanFactoryLocator.useBeanFactory("ctx");
testDAOimpl myDao = (testDAOimpl)beanFactoryReference.getFactory().getBean("testDAO");