简体   繁体   English

模式验证:使用Flyway的Hibernate生成的SQL代码缺少表[…]错误消息

[英]Schema-validation: missing table […] error message using flyway for a SQL code generated by Hibernate

I've been trying to deal with some problems regarding Flyway. 我一直在尝试解决有关Flyway的一些问题。 My situation is the following: I have two Java classes, which I'd like to migrate as two schemas. 我的情况如下:我有两个Java类,我想将其迁移为两个模式。 Let's name them Table and CustomTable. 我们将它们命名为Table和CustomTable。 My java classes look like: 我的Java类如下所示:

@Entity
public class xtable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
//getters, setters, constructors

@Entity
public class CustomTable{

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String a;
private String b;
private String c;
//getters, setters, constructors

My application.properties: 我的application.properties:

spring.flyway.url=${env.var1}
spring.flyway.user=${env.var2}
spring.flyway.password=${env.var3}
spring.jpa.hibernate.ddl-auto=validate

//If I use create-drop, hibernate creates it, but after that the validation fails

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
spring.logging.level.org.hibernate.SQL=debug
spring.jpa.show-sql=true
hibernate.temp.use_jdbc_metadata_defaults=true
spring.flyway.enabled=true

My build.gradle: 我的build.gradle:

plugins {
    id "org.flywaydb.flyway" version "5.2.4"
}

dependencies {
    implementation 'org.flywaydb:flyway-core'
}

The situation is so weird, because it does not even work with the auto-generated SQL code, which I let the program create without flyway. 这种情况太奇怪了,因为它甚至无法与自动生成的SQL代码一起使用,我让程序无需飞路即可创建该代码。

It looks like this: 看起来像这样:

    create table custom_table (
  id         bigint not null,
  a          varchar(255),
  b          varchar(255),
  c          varchar(255),
  xtable_id bigint,
  primary key (id)
)
  engine = InnoDB;

create table xtable (
  id                  bigint not null,
  name                varchar(255),
  xtable_id bigint,
  primary key (id)
)
  engine = InnoDB;

alter table custom_table
  add constraint FKep6vooglihwraille12muox9 foreign key (xtable_id) references xtable (id);

alter table xtable
  add constraint FK426q765pr4gv5wux6jaktafqk foreign key (custom_table_id) references custom_table (id);

I also don't understand why Hibernate creates one-one foreign key into each class, but the bigger problem is that I still get the error message 我也不明白为什么Hibernate在每个类中创建一个外键,但是更大的问题是我仍然收到错误消息

 Schema-validation: missing table [custom_table]

I tried renaming custom_table to customtable (and also renaming the class in Java), but the error message was the same. 我尝试将custom_table重命名为customtable(并重命名Java中的类),但是错误消息是相同的。

Have you ever met the same problem? 您遇到过同样的问题吗? Have you got any suggestions? 你有什么建议吗? I've been working on this problem for - at least - 2 days. 我已经针对这个问题进行了至少2天的工作。

I looked for relevant - or seemingly identical - topics here, but I couldn't find a good solution. 我在这里寻找相关的主题或看似相同的主题,但是找不到很好的解决方案。

Thank you. 谢谢。

Finally I got the problem. 终于我有了问题。 The problem was with inserting multiple foreign keys. 问题在于插入多个外键。 (So these two lines): (因此这两行):

alter table custom_table
add constraint FKep6vooglihwraille12muox9 foreign key (xtable_id) references xtable (id);

alter table xtable
  add constraint FK426q765pr4gv5wux6jaktafqk foreign key (custom_table_id) references custom_table (id);

I couldn't figure out, though, the reason why Flyway couldn't handle this, but when I recreated the whole structure with the two tables and another one containing the proper ID's, doing exactly the same thing in the whole project, it worked. 不过,我无法弄清楚Flyway无法处理此问题的原因,但是当我用两个表和另一个包含正确ID的表重新创建整个结构时,在整个项目中做同样的事情,它就起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java Spring Hibernate Schema-Validation:缺少表 - Java Spring Hibernate Schema-Validation: Missing Table 架构验证:缺少表 [hibernate_sequences] - Schema-validation: missing table [hibernate_sequences] 获取 entityManageFactory 错误。 模式验证:缺少表 [hibernate_sequence] - Getting entityManageFactory error. Schema-validation: missing table [hibernate_sequence] Hibernate + JPA:模式验证:缺少列 - Hibernate + JPA: Schema-validation: missing column Hibernate继承:模式验证:缺少列 - Hibernate inheritance: Schema-validation: missing column 使用Schema-validation验证除dbo结果以外的其他模式中的休眠访问表:缺少表 - Hibernate acessing table in schema other than dbo results with Schema-validation: missing table SqlServer2016,Hibernate 模式验证:缺少表,但表存在于数据库中 - SqlServer2016, Hibernate schema-validation: Missing table, but table exists in db 继承的实体类的休眠模式验证错误 - Hibernate Schema-validation error for the inherited entity class Spring Boot 项目由于 Schema-validation 无法运行:缺少序列 [hibernate_sequence] - Spring Boot project fails to run because of Schema-validation: missing sequence [hibernate_sequence] SchemaManagementException:模式验证:即使数据库中存在表,也缺少表 [chk_groups] - SchemaManagementException: Schema-validation: missing table [chk_groups] even when table is present in DB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM