How do i get rid of an "MySQLSyntaxErrorException" - java

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.

Related

Getting SQLServerException makeFromDriverError message 'could not prepare statement' and 'The connection is closed'

Recently as my production app has been increasing in users, I have started to receive the following errors (thousands):
org.hibernate.exception.GenericJDBCException: could not prepare
statement
Problem Id:com.microsoft.sqlserver.jdbc.SQLServerException at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError
The connection is closed.
Problem Id:com.microsoft.sqlserver.jdbc.SQLServerException at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError
Here are the full errors:
javax.persistence.PersistenceException: at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert
(AbstractEntityManagerImpl.java1763) at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert
(AbstractEntityManagerImpl.java1694) at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.find
(AbstractEntityManagerImpl.java1141) at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.find
(AbstractEntityManagerImpl.java1068) at
sun.reflect.GeneratedMethodAccessor65.invoke at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java43) at
java.lang.reflect.Method.invoke (Method.java498) at
org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke
(SharedEntityManagerCreator.java241) at com.sun.proxy.$Proxy51.find
at com.adaptive.xxxxxxx.data.JPAPersistenceAdapter.find
(JPAPersistenceAdapter.java27) at
com.adaptive.xxxxxxxxx.data.ChangeSetApplier2.applyChange
(ChangeSetApplier2.java257) at
com.adaptive.xxxxxxxx.data.ChangeSetApplier2.applyChanges
(ChangeSetApplier2.java59) at
com.adaptive.xxxxxxxx.services.EntityServiceImpl.applyChangeSet
(EntityServiceImpl.java64) at
sun.reflect.GeneratedMethodAccessor98.invoke at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java43) at
java.lang.reflect.Method.invoke (Method.java498) at
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection
(AopUtils.java317) at
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint
(ReflectiveMethodInvocation.java183) at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed
(ReflectiveMethodInvocation.java150) at
org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke
(MethodSecurityInterceptor.java64) at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed
(ReflectiveMethodInvocation.java172) at
org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation
(TransactionInterceptor.java96) at
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction
(TransactionAspectSupport.java260) at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke
(TransactionInterceptor.java94) at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed
(ReflectiveMethodInvocation.java172) at
org.granite.tide.spring.TideDataPublishingInterceptor$1.call
(TideDataPublishingInterceptor.java78) at
org.granite.tide.spring.TideDataPublishingWrapper.execute
(TideDataPublishingWrapper.java127) at
org.granite.tide.spring.TideDataPublishingInterceptor.invoke
(TideDataPublishingInterceptor.java75) at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed
(ReflectiveMethodInvocation.java172) at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke
(JdkDynamicAopProxy.java204) at
com.sun.proxy.$Proxy61.applyChangeSet at
sun.reflect.GeneratedMethodAccessor736.invoke at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java43) at
java.lang.reflect.Method.invoke (Method.java498) at
org.granite.messaging.service.ServiceInvocationContext.invoke
(ServiceInvocationContext.java72) at
org.granite.messaging.service.security.AbstractSecurityService.endAuthorization
(AbstractSecurityService.java108) at
org.granite.spring.security.SpringSecurity3Service.authorize
(SpringSecurity3Service.java294) at
org.granite.messaging.service.ServiceInvoker.invoke
(ServiceInvoker.java220) at
org.granite.messaging.amf.process.AMF3MessageProcessor.processRemotingMessage
(AMF3MessageProcessor.java141) at
org.granite.messaging.amf.process.AMF3MessageProcessor.process
(AMF3MessageProcessor.java60) at
org.granite.messaging.amf.process.AMF0MessageProcessor.process
(AMF0MessageProcessor.java79) at
org.granite.messaging.webapp.AMFEndpoint.serviceAMF
(AMFEndpoint.java91) at
org.granite.messaging.webapp.AMFEndpoint.service (AMFEndpoint.java66)
at org.granite.spring.ServerFilter.handle (ServerFilter.java331) at
org.springframework.web.servlet.DispatcherServlet.doDispatch
(DispatcherServlet.java925) at
org.springframework.web.servlet.DispatcherServlet.doService
(DispatcherServlet.java856) at
org.springframework.web.servlet.FrameworkServlet.processRequest
(FrameworkServlet.java936) at
org.springframework.web.servlet.FrameworkServlet.doPost
(FrameworkServlet.java838) at
javax.servlet.http.HttpServlet.service (HttpServlet.java648) at
org.springframework.web.servlet.FrameworkServlet.service
(FrameworkServlet.java812) at
javax.servlet.http.HttpServlet.service (HttpServlet.java729) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java292) at
org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java207) at
org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java240) at
org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java207) at
com.adaptive.xxxxxxxxx.servlet.CacheControlFilter.doFilter
(CacheControlFilter.java13) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java240) at
org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java207) at
org.apache.catalina.core.StandardWrapperValve.invoke
(StandardWrapperValve.java212) at
org.apache.catalina.core.StandardContextValve.invoke
(StandardContextValve.java106) at
org.apache.catalina.authenticator.AuthenticatorBase.invoke
(AuthenticatorBase.java502) at
org.apache.catalina.core.StandardHostValve.invoke
(StandardHostValve.java141) at
org.apache.catalina.valves.ErrorReportValve.invoke
(ErrorReportValve.java79) at
org.apache.catalina.valves.AbstractAccessLogValve.invoke
(AbstractAccessLogValve.java616) at
org.apache.catalina.valves.rewrite.RewriteValve.invoke
(RewriteValve.java480) at
org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineValve.java88) at
org.apache.catalina.connector.CoyoteAdapter.service
(CoyoteAdapter.java522) at
org.apache.coyote.http11.AbstractHttp11Processor.process
(AbstractHttp11Processor.java1095) at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process
(AbstractProtocol.java672) at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun
(NioEndpoint.java1502) at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run
(NioEndpoint.java1458) at
java.util.concurrent.ThreadPoolExecutor.runWorker
(ThreadPoolExecutor.java1149) at
java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java624) at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run
(TaskThread.java61) at java.lang.Thread.run (Thread.java748) Inner
exception org.hibernate.exception.GenericJDBCException handled at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert: at
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert
(StandardSQLExceptionConverter.java54) at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert
(SqlExceptionHelper.java126) at
org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement
(StatementPreparerImpl.java196) at
org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement
(StatementPreparerImpl.java160) at
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.prepareQueryStatement
(AbstractLoadPlanBasedLoader.java257) at
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeQueryStatement
(AbstractLoadPlanBasedLoader.java201) at
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad
(AbstractLoadPlanBasedLoader.java137) at
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad
(AbstractLoadPlanBasedLoader.java102) at
org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load
(AbstractLoadPlanBasedEntityLoader.java186) at
org.hibernate.persister.entity.AbstractEntityPersister.load
(AbstractEntityPersister.java4126) at
org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource
(DefaultLoadEventListener.java503) at
org.hibernate.event.internal.DefaultLoadEventListener.doLoad
(DefaultLoadEventListener.java468) at
org.hibernate.event.internal.DefaultLoadEventListener.load
(DefaultLoadEventListener.java213) at
org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad
(DefaultLoadEventListener.java275) at
org.hibernate.event.internal.DefaultLoadEventListener.onLoad
(DefaultLoadEventListener.java151) at
org.hibernate.internal.SessionImpl.fireLoad (SessionImpl.java1106)
at org.hibernate.internal.SessionImpl.access$2000
(SessionImpl.java176) at
org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load
(SessionImpl.java2587) at org.hibernate.internal.SessionImpl.get
(SessionImpl.java991) at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.find
(AbstractEntityManagerImpl.java1110) at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.find
(AbstractEntityManagerImpl.java1068) at
sun.reflect.GeneratedMethodAccessor65.invoke at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java43) at
java.lang.reflect.Method.invoke (Method.java498) at
org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke
(SharedEntityManagerCreator.java241) at com.sun.proxy.$Proxy51.find
at com.adaptive.xxxxxxx.data.JPAPersistenceAdapter.find
(JPAPersistenceAdapter.java27) at
com.adaptive.xxxxxxxxx.data.ChangeSetApplier2.applyChange
(ChangeSetApplier2.java257) at
com.adaptive.xxxxxxxxx.data.ChangeSetApplier2.applyChanges
(ChangeSetApplier2.java59) at
com.adaptive.xxxxxxx.services.EntityServiceImpl.applyChangeSet
(EntityServiceImpl.java64) at
sun.reflect.GeneratedMethodAccessor98.invoke at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java43) at
java.lang.reflect.Method.invoke (Method.java498) at
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection
(AopUtils.java317) at
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint
(ReflectiveMethodInvocation.java183) at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed
(ReflectiveMethodInvocation.java150) at
org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke
(MethodSecurityInterceptor.java64) at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed
(ReflectiveMethodInvocation.java172) at
org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation
(TransactionInterceptor.java96) at
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction
(TransactionAspectSupport.java260) at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke
(TransactionInterceptor.java94) at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed
(ReflectiveMethodInvocation.java172) at
org.granite.tide.spring.TideDataPublishingInterceptor$1.call
(TideDataPublishingInterceptor.java78) at
org.granite.tide.spring.TideDataPublishingWrapper.execute
(TideDataPublishingWrapper.java127) at
org.granite.tide.spring.TideDataPublishingInterceptor.invoke
(TideDataPublishingInterceptor.java75) at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed
(ReflectiveMethodInvocation.java172) at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke
(JdkDynamicAopProxy.java204) at
com.sun.proxy.$Proxy61.applyChangeSet at
sun.reflect.GeneratedMethodAccessor736.invoke at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java43) at
java.lang.reflect.Method.invoke (Method.java498) at
org.granite.messaging.service.ServiceInvocationContext.invoke
(ServiceInvocationContext.java72) at
org.granite.messaging.service.security.AbstractSecurityService.endAuthorization
(AbstractSecurityService.java108) at
org.granite.spring.security.SpringSecurity3Service.authorize
(SpringSecurity3Service.java294) at
org.granite.messaging.service.ServiceInvoker.invoke
(ServiceInvoker.java220) at
org.granite.messaging.amf.process.AMF3MessageProcessor.processRemotingMessage
(AMF3MessageProcessor.java141) at
org.granite.messaging.amf.process.AMF3MessageProcessor.process
(AMF3MessageProcessor.java60) at
org.granite.messaging.amf.process.AMF0MessageProcessor.process
(AMF0MessageProcessor.java79) at
org.granite.messaging.webapp.AMFEndpoint.serviceAMF
(AMFEndpoint.java91) at
org.granite.messaging.webapp.AMFEndpoint.service (AMFEndpoint.java66)
at org.granite.spring.ServerFilter.handle (ServerFilter.java331) at
org.springframework.web.servlet.DispatcherServlet.doDispatch
(DispatcherServlet.java925) at
org.springframework.web.servlet.DispatcherServlet.doService
(DispatcherServlet.java856) at
org.springframework.web.servlet.FrameworkServlet.processRequest
(FrameworkServlet.java936) at
org.springframework.web.servlet.FrameworkServlet.doPost
(FrameworkServlet.java838) at
javax.servlet.http.HttpServlet.service (HttpServlet.java648) at
org.springframework.web.servlet.FrameworkServlet.service
(FrameworkServlet.java812) at
javax.servlet.http.HttpServlet.service (HttpServlet.java729) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java292) at
org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java207) at
org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java240) at
org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java207) at
com.adaptive.xxxxxx.servlet.CacheControlFilter.doFilter
(CacheControlFilter.java13) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java240) at
org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java207) at
org.apache.catalina.core.StandardWrapperValve.invoke
(StandardWrapperValve.java212) at
org.apache.catalina.core.StandardContextValve.invoke
(StandardContextValve.java106) at
org.apache.catalina.authenticator.AuthenticatorBase.invoke
(AuthenticatorBase.java502) at
org.apache.catalina.core.StandardHostValve.invoke
(StandardHostValve.java141) at
org.apache.catalina.valves.ErrorReportValve.invoke
(ErrorReportValve.java79) at
org.apache.catalina.valves.AbstractAccessLogValve.invoke
(AbstractAccessLogValve.java616) at
org.apache.catalina.valves.rewrite.RewriteValve.invoke
(RewriteValve.java480) at
org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineValve.java88) at
org.apache.catalina.connector.CoyoteAdapter.service
(CoyoteAdapter.java522) at
org.apache.coyote.http11.AbstractHttp11Processor.process
(AbstractHttp11Processor.java1095) at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process
(AbstractProtocol.java672) at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun
(NioEndpoint.java1502) at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run
(NioEndpoint.java1458) at
java.util.concurrent.ThreadPoolExecutor.runWorker
(ThreadPoolExecutor.java1149) at
java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java624) at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run
(TaskThread.java61) at java.lang.Thread.run (Thread.java748) Inner
exception com.microsoft.sqlserver.jdbc.SQLServerException handled at
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert:
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError
(SQLServerException.java191) at
com.microsoft.sqlserver.jdbc.SQLServerConnection.checkClosed
(SQLServerConnection.java395) at
com.microsoft.sqlserver.jdbc.SQLServerConnection.prepareStatement
(SQLServerConnection.java2292) at
com.microsoft.sqlserver.jdbc.SQLServerConnection.prepareStatement
(SQLServerConnection.java1931) at
sun.reflect.GeneratedMethodAccessor731.invoke at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java43) at
java.lang.reflect.Method.invoke (Method.java498) at
com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask.run
(GooGooStatementCache.java546) at
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run
(ThreadPoolAsynchronousRunner.java648)
com.microsoft.sqlserver.jdbc.SQLServerException: at
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError
(SQLServerException.java191) at
com.microsoft.sqlserver.jdbc.SQLServerConnection.checkClosed
(SQLServerConnection.java395) at
com.microsoft.sqlserver.jdbc.SQLServerConnection.prepareStatement
(SQLServerConnection.java2292) at
com.microsoft.sqlserver.jdbc.SQLServerConnection.prepareStatement
(SQLServerConnection.java1931) at
sun.reflect.GeneratedMethodAccessor731.invoke at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java43) at
java.lang.reflect.Method.invoke (Method.java498) at
com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask.run
(GooGooStatementCache.java546) at
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run
(ThreadPoolAsynchronousRunner.java648)
I am wondering if it has to do with c3p0 connection pooling.
I am not 100% if the information is being taken from the app-config file, vs the hibernate.properties file.
I have attached both files, as well, you can see the relevant information included inline below:
app-config.xml:
<!-- Data source --
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"
<property name="driverClass" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" /
<property name="jdbcUrl" value="jdbc:sqlserver://xxxxxxxx.database.windows.net:1433;database=XXXXX;user=XXXXXXXX;password=XXXXXXXXX;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;" /
<!-- Pool properties --
<property name="minPoolSize" value="3" /
<property name="maxPoolSize" value="120" /
<property name="maxStatements" value="120" /
<property name="preferredTestQuery" value="SELECT 1" /
<property name="maxIdleTime" value="300" /
<property name="testConnectionOnCheckin" value="true" /
<property name="idleConnectionTestPeriod" value="30" /
</bean>
hibernate.properties:
# JDBC Connection information
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost/mkbkwebgds
jdbc.username=xxxxxxxx
jdbc.password=xxxxxxxxxxx
# Hibernate 3 configuration
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.jdbc.batch_size=20
hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
hibernate.transaction.factory_class=org.hibernate.transaction.JDBCTransactionFactory
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.hbm2ddl.auto=update
hibernate.c3p0.acquire_increment=3
hibernate.c3p0.idle_test_period=1000
hibernate.c3p0.timeout=2520
hibernate.c3p0.min_size=3
hibernate.c3p0.max_size=20
hibernate.c3p0.max_statements=0
hibernate.c3p0.preferredTestQuery=select 1;
I had not changed anything in the app or on the server since starting to find these errors.
Any help to solve this would be greatly appreciated.
Your hibernate.properties file is setting up a MySql driver while your app-config.xml is setting up a SQL Server driver. Since the error message mentions SQL Server I'm gussing that your app-config.xml is what's used. (Your hibernate.properties also sets hibernate.hbm2ddl.auto=update which should never ever be used in production).
app-config.xml sets testConnectionOnCheckin to true. This means that the connections are validated when they are returned to the pool. It also sets idleConnectionTestPeriod to 30 which means that your idle connections are validated every 30 seconds. This makes it unlikely, but not impossible, that the problem is the database closing the connections while they are pooled.
You could try replacing testConnectionOnCheckIn with testConnectionOnCheckout. This would fix any problems with the database closing the connection on you for sure. If this doesn't work then the problem is the program actively closing the connection and then trying to use it again.
I have the same issue when trying to open connection manually in my Spring Repository. After I start using JdbcTemplate error dissapeared

Issue connecting to mysql database using hibernate.xml

I am unable to connect to a mysql database using xml. I have no problem using an hibernate.properties file, but when i substitute it with an xml it doesn't work. The xml in main/resources is
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/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://localhost:3306/ifinances</property>
<property name="connection.username">infinite</property>
<property name="connection.password">skills</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<mapping class="com.infiniteskills.data.entities.User" />
</session-factory>
</hibernate-configuration>
I have a utility SessionFactory class that returns this
private static SessionFactory buildSessionFactory() {
try {
Configuration configuration = new Configuration();
return configuration
.buildSessionFactory(new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Error in building the factory");
}
}
After i retrieve it and i call the method .openSession() i have the following error
WARN - HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
WARN - HHH000342: Could not obtain connection to query metadata : The application must supply JDBC connections
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:271)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
at com.infiniteskills.data.HibernateUtil.buildSessionFactory(HibernateUtil.java:18)
at com.infiniteskills.data.HibernateUtil.<clinit>(HibernateUtil.java:11)
at com.infiniteskills.data.Application.main(Application.java:18)
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)
... 15 more
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.infiniteskills.data.Application.main(Application.java:18)
Caused by: java.lang.RuntimeException: Error in building the factory
at com.infiniteskills.data.HibernateUtil.buildSessionFactory(HibernateUtil.java:22)
at com.infiniteskills.data.HibernateUtil.<clinit>(HibernateUtil.java:11)
... 1 more
Add in your library path MySQL Connector JDBC driver for MySQL (JAR)
Link [ https://dev.mysql.com/downloads/connector/j ]
You are not .configuring() the Configuration object with the hibernate.cfg.xml
so it's not picking up those properties.
Configuration configuration = new Configuration();
configuration.configure("hibernate.cfg.xml"); //Resource path or File
Your hibernate config file is using wrong parameter names. Correct param names are as below:
hibernate.connection.driver_class
hibernate.connection.url
hibernate.connection.username
hibernate.connection.password
hibernate.dialect
hibernate.show_sql
Correct your param names and try again.
Refer this link for detailed list of param names: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html

hibernate 5 configuration for oracle11g in eclipse

I am trying to configure hibernate 5 to access oracle 11 g in eclipse.
hibernate.cfg.xml is as follows:
In following xml i have specified database credentials(url, username and password),dilect, mapping class, show_sql . I want to ask if I missed any important property.
<?xml version='1.0' encoding='utf-8'?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<!-- <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:#127.0.0.1:1521:orcl</property> -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:#127.0.0.1:1521:XE</property>
<property name="connection.username">SYSTEM</property>
<property name="connection.password">motog</property>
<mapping class="com.demo.one.Hello"/>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">
org.hibernate.dialect.OracleDialect
</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<property name="cache.use_query_cache">true</property>
<property name="cache.use_second_level_cache">true</property>
<property name="cache.use_structured_entries">true</property>
<property name="cache.region.factory_class">org.hibernate.cache.EhCacheRegionFactory</property>
<property name="net.sf.ehcache.configurationResourceName">/hibernate-config/ehcache.xml</property>
<!-- Echo all executed SQL to stdout -->
<property name="hibernate.show_sql">true</property>
<mapping resource="hibernate-config/domain/Event.hbm.xml"/>
<mapping resource="hibernate-config/domain/Person.hbm.xml"/>
<mapping resource="hibernate-config/domain/PhoneNumber.hbm.xml"/>
<mapping resource="hibernate-config/domain/Account.hbm.xml"/>
<mapping resource="hibernate-config/domain/HolidayCalendar.hbm.xml"/>
<mapping resource="hibernate-config/domain/Item.hbm.xml"/>
</session-factory>
</hibernate-configuration>
[image specifies project structure and imported libraries][1]
Defined Hello class as Table name by using #Entity and userId as primary key by using #Id
Hello.java:
package com.demo.one;
import javax.persistence.Entity;
import javax.persistence.Id;
#Entity
public class Hello {
#Id
private int userId;
private String userName;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
} // end of Hello.java
Following class tries to save instance of Hello in database.
OracleTest.java:
package com.demo.one;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class OracleTest {
public static void main(String[] args) {
Hello z = new Hello();
z.setUserId(2);
z.setUserName("ashish");
SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
session.save(z);
session.getTransaction().commit();
}
} // End of OracleTest.java
I am trying to save Hello class's object in oracle 11g XE database(resides on my local machine) , OracleTest.java is written for that.
I am getting following errors.
Jan 17, 2016 6:08:01 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.0.7.Final}
Jan 17, 2016 6:08:01 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jan 17, 2016 6:08:01 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number -1 and column -1 in RESOURCE hibernate.cfg.xml. Message: cvc-complex-type.2.4.a: Invalid content was found starting with element 'property'. One of '{"http://www.hibernate.org/xsd/orm/cfg":mapping, "http://www.hibernate.org/xsd/orm/cfg":class-cache, "http://www.hibernate.org/xsd/orm/cfg":collection-cache, "http://www.hibernate.org/xsd/orm/cfg":event, "http://www.hibernate.org/xsd/orm/cfg":listener}' is expected.
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:133)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65)
at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:163)
at org.hibernate.cfg.Configuration.configure(Configuration.java:259)
at org.hibernate.cfg.Configuration.configure(Configuration.java:245)
at com.demo.one.OracleTest.main(OracleTest.java:13)
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException; cvc-complex-type.2.4.a: Invalid content was found starting with element 'property'. One of '{"http://www.hibernate.org/xsd/orm/cfg":mapping, "http://www.hibernate.org/xsd/orm/cfg":class-cache, "http://www.hibernate.org/xsd/orm/cfg":collection-cache, "http://www.hibernate.org/xsd/orm/cfg":event, "http://www.hibernate.org/xsd/orm/cfg":listener}' is expected.]
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Unknown Source)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:126)
... 6 more
Caused by: org.xml.sax.SAXParseException; cvc-complex-type.2.4.a: Invalid content was found starting with element 'property'. One of '{"http://www.hibernate.org/xsd/orm/cfg":mapping, "http://www.hibernate.org/xsd/orm/cfg":class-cache, "http://www.hibernate.org/xsd/orm/cfg":collection-cache, "http://www.hibernate.org/xsd/orm/cfg":event, "http://www.hibernate.org/xsd/orm/cfg":listener}' is expected.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXEventConnector.handleStartElement(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXEventConnector.bridge(Unknown Source)
... 9 more
please guide me, its my first encounter with hibernate.
PS: please check attached image. link is at the bottom.
regards
ashish
[1]: http://i.stack.imgur.com/DBYxu.png
The error message tells you that it's not expecting a <property> element somewhere. Instead, it expects a <mapping> element, or a <class-cache> element, or...
And indeed, the DTD has the following definition:
<!ELEMENT session-factory (property*, mapping*, (class-cache|collection-cache)*, event*, listener*)>
This means that, under <session-factory>, you're supposed to have 0 or more <property> elements, then 0 or more <mapping> elements.
But your xml file has
<property name="connection.password">motog</property>
<mapping class="com.demo.one.Hello"/>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
So you have a <mapping>element in the middle of <property> elements. That is thus invalid.

MVC Template Project dont see hibernate.cfg.xml

I'm new at Spring MVC. I'm using STS and I've created Spring MVC Template Project (which uses Maven by default). I'm trying to use Hibernate and i know that in default Java Projects i have to put hibernate.xml.cfg in /src folder. I've read that in my case (with Spring MVC Template with maven) i have to put hibernate.cfg.xml in src/main/resources and in /WEB-INF/classes. But it didn't help too. I still have ClassNotFoundException:
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/mvc] threw exception [Handler processing failed; nested exception is java.lang.ExceptionInInitializerError] with root cause
java.lang.ClassNotFoundException: org.dom4j.DocumentException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at com.andrew.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:18)
at com.andrew.hibernate.DAO.getStudent(DAO.java:48)
at com.andrew.mvc.HomeController.home(HomeController.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
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:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
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:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
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:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Here is my hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="connection.url">jdbc:sqlserver://localhost:1433</property>
<property name="connection.username">hibernate</property>
<property name="connection.password">123456</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Mapping files -->
<mapping class="com.andrew.ModelPackage.Student"/>
<mapping class="com.andrew.ModelPackage.Subject"/>
</session-factory>
</hibernate-configuration>
My HibernateUtil class:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
//AnnotationConfiguration
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Maybe i should write something about hibernate.cfg.xml in web.xml or in servlet-context.xml? I'm fighting with this problem about 7 hours and i tried even put hibernate.cfg.xml in every folder in the project but it didn't helped.
IMO is not a problem with the location of your hibernate.cfx.xml, but looks like a missing library. You should add the dom4j.jar in your classpath.

Hibernate/MySQL Connection Timeout

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.

Categories