问题描述
@Entity
@Table(name =META_INF )
@Inheritance(strategy = InheritanceType.JOINED)
公共类META_INF {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@NotBlank
@Column(nullable = false)
私有布尔aa;
@ManyToOne
私人用户bb;
@NotBlank
@JoinColumn(nullable = false)
@ManyToOne
私人用户cc;
@NotBlank
@Column(nullable = false)
private Boolean dd;
private String ee;
@NotBlank
@Column(nullable = false)
私有布尔值ff;
@NotBlank
@JoinColumn(nullable = false,name =tt)
@ManyToOne
私人AZE tt;
$ b实体2: strong> @Entity
@Table(name =QWE,uniqueConstraints = {
@UniqueConstraint (columnNames = {a,b,c,d})})
public class QWE extends META_INF {
@NotBlank
@JoinColumn( nullable = false,name =a)
@ManyToOne
private PIL_P_TRATMNT a;
@NotBlank
@Column(nullable = false,name =b)
private String b;
@NotBlank
@Min(value = 0)
@Digits(integer = 3,fraction = 0)
@Column(nullable = false,name = c)
private int c;
@NotBlank
@Min(value = 0)
@Digits(integer = 3,fraction = 0)
@Column(nullable = false,name = d)
private int d;
@NotBlank
@Column(nullable = false,name =e)
private String e;
@Column(name =f)
private String f;
@NotBlank
@Column(nullable = false,name =g)
private String g;
@NotBlank
@Column(nullable = false,name =h)
private String h;
@NotBlank
@Column(nullable = false,name =i)
private String i;
@Digits(integer = 2,fraction = 0)
@Column(name =j)
private int j;
public QWE(){
}
}
和许多其他实体。
application.properties 指定访问数据库的凭据:
jdbc.driverClassName = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql:// localhost:3306 /横向
jdbc.username = root
jdbc.password = root
hibernate.dialect = org.hibernate.dialect.MySQLDialect
hibernate.show_sql = true
hibernate。 format_sql = true
hibernate.hbm2ddl.auto =创建
数据库为空。当我尝试运行SpringMVC应用程序时,它给了我这个错误(表格以数据库创建):
WARN:org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl - GenerationTarget遇到异常接受命令:无法执行命令[
alter table QWE
drop
外键FK5f4s5qg3vma47jthit51i7wvy]
org.hibernate.tool.schema.spi.CommandAcceptanceException:无法在org.hibernate.tool执行命令[
alter table QWE
drop
foreign key FK5f4s5qg3vma47jthit51i7wvy]
。 schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:63)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:370)
at org.hibernate。 tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:355)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applyConstraint在org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata中删除(SchemaDropperImpl.java:327)
(SchemaDropperImpl.java:229)在org.hibernate.tool.schema.internal.SchemaDropperImpl中
。 (org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:125)
在org.hibernate.tool.schema.internal.SchemaDropperImpl中执行(SchemaDropperImpl.java:153)
。 doDrop(SchemaDropperImpl.java:111)
处org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:137)
。进程(SchemaManagementToolCoordinator.java:64)
在org.hibernate.internal.SessionFactoryImpl。< init>(SessionFactoryImpl.java:458)
在org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl .java:465)$ or $
在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java: 708)
在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
在org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:416)
在org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:401)
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
。在组织.bringframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractB eanFactory $ 1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support .AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
在org.springframework.beans.factory.support .DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at org.springframework.beans.factory.support .DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545 )
处org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
(AutowiredAnnotationBeanPostProcessor.java:331 )
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) )美元,org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482 b $ b)
在org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java: 306)
在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework .beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
在org.springframework .beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context .support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
在org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
在org.springframework.web.context.ContextLoader .initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at io.undertow.servlet.core.ApplicationLi steners.contextInitialized(ApplicationListeners.java:187)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:198)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService。 startContext(UndertowDeploymentService.java:100)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService $ 1.run(UndertowDeploymentService.java:82)
在java.util.concurrent.Executors $ RunnableAdapter.call (Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)$在java.util.concurrent.ThreadPoolExecutor $ b.b $ Worker.run(ThreadPoolExecutor.java:617)$ b $在java.lang.Thread.run(Thread.java:745)
在org.jboss。 threads.JBossThread.run(JBossThread.java:320)
引起:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:表'transverse.qwe'不存在
我得到了所有其他实体的相同错误
预计在数据库存在时出现此错误空。这是当你指定hbm2ddl.auto = create时会发生什么。
- 按此顺序执行脚本
alter table< TABLE NAME>放弃外键< CONSTRAINT NAME>;
放置表< TABLE NAME>如果存在
创建表< TABLE NAME>
alter table< TABLE NAME>添加约束< CONSTRAINT NAME>
当hibernate第一次使用这些设置运行脚本时,自从消费者缺失将记录为警告。 DROP脚本不会失败,因为它们具有if exists检查。
第二次运行时,约束条件将存在,并且 alter table drop constraint
语句不会失败。因此你不会看到任何错误。
Entity 1:
@Entity
@Table(name = "META_INF")
@Inheritance(strategy = InheritanceType.JOINED)
public class META_INF {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@NotBlank
@Column(nullable = false)
private Boolean aa;
@ManyToOne
private USER bb;
@NotBlank
@JoinColumn(nullable = false)
@ManyToOne
private USER cc;
@NotBlank
@Column(nullable = false)
private Boolean dd;
private String ee;
@NotBlank
@Column(nullable = false)
private Boolean ff;
@NotBlank
@JoinColumn(nullable = false, name = "tt")
@ManyToOne
private AZE tt;
}
Entity 2:
@Entity
@Table(name = "QWE", uniqueConstraints = {
@UniqueConstraint(columnNames = { "a", "b", "c", "d" }) })
public class QWE extends META_INF {
@NotBlank
@JoinColumn(nullable = false, name = "a")
@ManyToOne
private PIL_P_TRATMNT a;
@NotBlank
@Column(nullable = false, name = "b")
private String b;
@NotBlank
@Min(value = 0)
@Digits(integer = 3, fraction = 0)
@Column(nullable = false, name = "c")
private int c;
@NotBlank
@Min(value = 0)
@Digits(integer = 3, fraction = 0)
@Column(nullable = false, name = "d")
private int d;
@NotBlank
@Column(nullable = false, name = "e")
private String e;
@Column(name = "f")
private String f;
@NotBlank
@Column(nullable = false, name = "g")
private String g;
@NotBlank
@Column(nullable = false, name = "h")
private String h;
@NotBlank
@Column(nullable = false, name = "i")
private String i;
@Digits(integer = 2, fraction = 0)
@Column(name = "j")
private int j;
public QWE () {
}
}
and lot of other entities..
application.properties to specify the credentials to access to the database:
jdbc.driverClassName = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql://localhost:3306/transverse
jdbc.username = root
jdbc.password = root
hibernate.dialect = org.hibernate.dialect.MySQLDialect
hibernate.show_sql = true
hibernate.format_sql = true
hibernate.hbm2ddl.auto=create
the database is empty. when I try to run the SpringMVC app, it gives me this error ( tables are created in DB ):
WARN : org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl - GenerationTarget encountered exception accepting command : Unable to execute command [
alter table QWE
drop
foreign key FK5f4s5qg3vma47jthit51i7wvy]
org.hibernate.tool.schema.spi.CommandAcceptanceException: Unable to execute command [
alter table QWE
drop
foreign key FK5f4s5qg3vma47jthit51i7wvy]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:63)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:370)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:355)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applyConstraintDropping(SchemaDropperImpl.java:327)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:229)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:153)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:125)
at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:111)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:137)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:64)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:458)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:465)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:416)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:401)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:198)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'transverse.qwe' doesn't exist
i got the same error for all other entities
You mentioned:
It is expected that you get this error when the database is empty. Here is what will happen when you specify hbm2ddl.auto=create.
--Execute the scripts in this order
alter table <TABLE NAME> drop foreign key <CONSTRAINT NAME>;
drop table <TABLE NAME> if exists
create table <TABLE NAME>
alter table <TABLE NAME> add constraint <CONSTRAINT NAME>
When hibernate runs the scripts with these settings the very first time, the errors which are detected since the constriants are missing will be logged as warnings. The DROP scripts will not fail since they have the if exists check.
On a second run the constraints will exist and the alter table drop constraint
statements will not fail. Hence you will not see any errors.
这篇关于表不存在:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!