gpt4 book ai didi

java - 我如何摆脱 "MySQLSyntaxErrorException"

转载 作者:搜寻专家 更新时间:2023-10-30 20:26:30 29 4
gpt4 key购买 nike

我目前正在使用 hibernate 构建一个基于网络的小工具。我使用 Tomcat v7.0 服务器在 eclipse 中测试该站点。我的数据库在 Linux 上使用 MySQL 5.6 版。

现在,每次我运行该程序,在服务器上启动我的 index.xhtml 时,我都会收到如下所示的异常错误消息:

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)

我的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>

程序本身正常运行并按照预期的方式工作,但是当控制台每隔一行打印此消息时,我很难验证其余的控制台输出。

值得一提的是,我在添加关键字validate后开始收到此消息在<property name="hibernate.hbm2ddl.auto">validate</property> .

这个表应该在哪里,最重要的是,我如何摆脱这个消息?

最佳答案

首先你需要了解hibernate映射到ddl,hbm2ddl.auto设置。

来自文档 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

验证:验证模式,不对数据库进行任何更改。

更新:更新模式。

create: 创建模式,销毁之前的数据。

create-drop:在 session 结束时删除模式。

您的配置无法验证架构,因为它找不到 information_schema.system_sequences。我认为这是因为您选择了方言。

尝试将 org.hibernate.dialect.HSQLDialect 替换为 org.hibernate.dialect.MySQLDialect

查看文档 url 以选择正确的方言,并验证其余配置。

MySQL hibernate 方言:

MySQL               org.hibernate.dialect.MySQLDialect
MySQL with InnoDB org.hibernate.dialect.MySQLInnoDBDialect
MySQL with MyISAM org.hibernate.dialect.MySQLMyISAMDialect

information_schema是MySQL自带的信息数据库。它包含有关在其数据库服务器中维护的所有其他(您自己的)数据库的所有信息。

关于java - 我如何摆脱 "MySQLSyntaxErrorException",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31334917/

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