表不存在:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

时间:2016-04-29 00:03:51

标签: hibernate spring-mvc wildfly

实体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;


}

实体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 () {
    }   

}

以及许多其他实体..

application.properties 指定访问数据库的凭据:

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

数据库为空。当我尝试运行SpringMVC应用程序时,它会给我这个错误(表格在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

我的所有其他实体都有同样的错误

1 个答案:

答案 0 :(得分:1)

你提到了:

  

数据库为空。当我尝试运行SpringMVC应用程序时,它给了我这个错误。

当数据库为空时,预计会出现此错误。以下是指定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>    

当hibernate第一次运行带有这些设置的脚本时,自缺少行为者以来检测到的错误将记录为警告。 DROP脚本不会失败,因为它们具有if exists检查。

第二次运行时,约束将存在,alter table drop constraint语句不会失败。因此,您不会看到任何错误。