jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.54k stars 4.02k forks source link

Changing Parent Leads to DB Errors #21324

Closed vw98075 closed 1 year ago

vw98075 commented 1 year ago
Overview of the issue

Entities & their relationship:

entity P {
    note String
}

entity S {
    symbol String pattern(/^[a-zA-Z0-9.]{1,8}$/) required
}

entity W {
    symbol String 
}

relationship ManyToOne{
    P{w(symbol)} to S
}

Import the JDL file. And change the parent of P as

relationship ManyToOne{
    P{w(symbol)} to W
}

Import the JDL file again. And all or most of front-end and back-end code has been changed, but something is not missing in the Liqubase.

2023-03-06T15:31:49.525-08:00 ERROR 68463 --- [geparent-task-1] t.j.c.liquibase.AsyncSpringLiquibase     : Liquibase could not start correctly, your database is NOT ready: liquibase.exception.MigrationFailedException: Migration failed for changeset config/liquibase/changelog/20230306232343_added_entity_constraints_P.xml::20230306232343-2::jhipster:_     Reason: liquibase.exception.DatabaseException: Column "W_ID" not found; SQL statement:_ALTER TABLE PUBLIC.p ADD CONSTRAINT fk_pp__ww_id FOREIGN KEY (w_id) REFERENCES PUBLIC.w (id) [42122-214] [Failed SQL: (42122) ALTER TABLE PUBLIC.p ADD CONSTRAINT fk_pp__ww_id FOREIGN KEY (w_id) REFERENCES PUBLIC.w (id)] 

liquibase.exception.LiquibaseException: liquibase.exception.MigrationFailedException: Migration failed for changeset config/liquibase/changelog/20230306232343_added_entity_constraints_P.xml::20230306232343-2::jhipster:
     Reason: liquibase.exception.DatabaseException: Column "W_ID" not found; SQL statement:
ALTER TABLE PUBLIC.p ADD CONSTRAINT fk_pp__ww_id FOREIGN KEY (w_id) REFERENCES PUBLIC.w (id) [42122-214] [Failed SQL: (42122) ALTER TABLE PUBLIC.p ADD CONSTRAINT fk_pp__ww_id FOREIGN KEY (w_id) REFERENCES PUBLIC.w (id)]
        at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:126)
        at liquibase.Liquibase.lambda$null$0(Liquibase.java:263)
        at liquibase.Scope.lambda$child$0(Scope.java:180)
        at liquibase.Scope.child(Scope.java:189)
        at liquibase.Scope.child(Scope.java:179)
        at liquibase.Scope.child(Scope.java:158)
        at liquibase.Scope.child(Scope.java:243)
        at liquibase.Liquibase.lambda$update$1(Liquibase.java:262)
        at liquibase.Scope.lambda$child$0(Scope.java:180)
        at liquibase.Scope.child(Scope.java:189)
        at liquibase.Scope.child(Scope.java:179)
        at liquibase.Scope.child(Scope.java:158)
        at liquibase.Liquibase.runInScope(Liquibase.java:2414)
        at liquibase.Liquibase.update(Liquibase.java:209)
        at liquibase.Liquibase.update(Liquibase.java:195)
        at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:314)
        at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:269)
        at org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase.afterPropertiesSet(DataSourceClosingSpringLiquibase.java:46)
        at tech.jhipster.config.liquibase.AsyncSpringLiquibase.initDb(AsyncSpringLiquibase.java:118)
        at tech.jhipster.config.liquibase.AsyncSpringLiquibase.lambda$afterPropertiesSet$0(AsyncSpringLiquibase.java:93)
        at tech.jhipster.async.ExceptionHandlingAsyncTaskExecutor.lambda$createWrappedRunnable$1(ExceptionHandlingAsyncTaskExecutor.java:79)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: liquibase.exception.MigrationFailedException: Migration failed for changeset config/liquibase/changelog/20230306232343_added_entity_constraints_P.xml::20230306232343-2::jhipster:
     Reason: liquibase.exception.DatabaseException: Column "W_ID" not found; SQL statement:
ALTER TABLE PUBLIC.p ADD CONSTRAINT fk_pp__ww_id FOREIGN KEY (w_id) REFERENCES PUBLIC.w (id) [42122-214] [Failed SQL: (42122) ALTER TABLE PUBLIC.p ADD CONSTRAINT fk_pp__ww_id FOREIGN KEY (w_id) REFERENCES PUBLIC.w (id)]
        at liquibase.changelog.ChangeSet.execute(ChangeSet.java:708)
        at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:56)
        at liquibase.changelog.ChangeLogIterator$2.lambda$null$0(ChangeLogIterator.java:113)
        at liquibase.Scope.lambda$child$0(Scope.java:180)
        at liquibase.Scope.child(Scope.java:189)
        at liquibase.Scope.child(Scope.java:179)
        at liquibase.Scope.child(Scope.java:158)
        at liquibase.changelog.ChangeLogIterator$2.lambda$run$1(ChangeLogIterator.java:112)
        at liquibase.Scope.lambda$child$0(Scope.java:180)
        at liquibase.Scope.child(Scope.java:189)
        at liquibase.Scope.child(Scope.java:179)
        at liquibase.Scope.child(Scope.java:158)
        at liquibase.Scope.child(Scope.java:243)
        at liquibase.changelog.ChangeLogIterator$2.run(ChangeLogIterator.java:93)
        at liquibase.Scope.lambda$child$0(Scope.java:180)
        at liquibase.Scope.child(Scope.java:189)
        at liquibase.Scope.child(Scope.java:179)
        at liquibase.Scope.child(Scope.java:158)
        at liquibase.Scope.child(Scope.java:243)
        at liquibase.Scope.child(Scope.java:247)
        at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:65)
        ... 23 common frames omitted
Caused by: liquibase.exception.DatabaseException: Column "W_ID" not found; SQL statement:
ALTER TABLE PUBLIC.p ADD CONSTRAINT fk_pp__ww_id FOREIGN KEY (w_id) REFERENCES PUBLIC.w (id) [42122-214] [Failed SQL: (42122) ALTER TABLE PUBLIC.p ADD CONSTRAINT fk_pp__ww_id FOREIGN KEY (w_id) REFERENCES PUBLIC.w (id)]
        at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:440)
        at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:78)
        at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:161)
        at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1299)
        at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1281)
        at liquibase.changelog.ChangeSet.execute(ChangeSet.java:673)
        ... 43 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "W_ID" not found; SQL statement:
ALTER TABLE PUBLIC.p ADD CONSTRAINT fk_pp__ww_id FOREIGN KEY (w_id) REFERENCES PUBLIC.w (id) [42122-214]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:502)
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:477)
        at org.h2.message.DbException.get(DbException.java:223)
        at org.h2.message.DbException.get(DbException.java:199)
        at org.h2.table.Table.getColumn(Table.java:749)
        at org.h2.table.IndexColumn.mapColumns(IndexColumn.java:184)
        at org.h2.command.ddl.AlterTableAddConstraint.tryUpdate(AlterTableAddConstraint.java:214)
        at org.h2.command.ddl.AlterTableAddConstraint.update(AlterTableAddConstraint.java:72)
        at org.h2.command.ddl.AlterTable.update(AlterTable.java:46)
        at org.h2.command.CommandContainer.update(CommandContainer.java:169)
        at org.h2.command.Command.executeUpdate(Command.java:252)
        at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:252)
        at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:223)
        at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:94)
        at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
        at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:436)
        ... 48 common frames omitted
Motivation for or Use Case
Reproduce the error
Related issues
Suggest a Fix
JHipster Version(s)

7.9.3

JHipster configuration
{
  "generator-jhipster": {
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "baseName": "changeparent",
    "blueprints": [],
    "buildTool": "gradle",
    "cacheProvider": "ehcache",
    "clientFramework": "vue",
    "clientPackageManager": "npm",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "creationTimestamp": 1678144776138,
    "databaseType": "sql",
    "devDatabaseType": "h2Memory",
    "devServerPort": 9060,
    "dtoSuffix": "DTO",
    "enableGradleEnterprise": false,
    "enableHibernateCache": false,
    "enableSwaggerCodegen": false,
    "enableTranslation": false,
    "entities": ["P", "S", "W"],
    "entitySuffix": "",
    "jhiPrefix": "jhi",
    "jhipsterVersion": "7.9.3",
    "jwtSecretKey": "NjAyNTNmNWVlNjQxYTFjN2RhZDNiMWI1NWEyZTI2ZTZjOTQ5ZTVmMzdhOTQ1ZjBhMTdiNDQxOWQzNzZiY2RlNjZjNzI4Mjk0MDgwMWI3YzY0MjNmYmIxMjhhZDUyM2E4OGU0MjFmYzBiNDFkMzE3MGIzZDBlMDhkMTAzYjc2Yjg=",
    "languages": ["en", "fr"],
    "lastLiquibaseTimestamp": 1678145025000,
    "messageBroker": false,
    "microfrontend": false,
    "microfrontends": [],
    "monorepository": true,
    "nativeLanguage": "en",
    "otherModules": [],
    "packageName": "com.mycompany.myapp",
    "pages": [],
    "prodDatabaseType": "postgresql",
    "reactive": false,
    "searchEngine": false,
    "serverPort": "8080",
    "serverSideOptions": [],
    "serviceDiscoveryType": "no",
    "skipCheckLengthOfIdentifier": false,
    "skipClient": false,
    "skipCommitHook": true,
    "skipFakeData": false,
    "skipUserManagement": false,
    "testFrameworks": [],
    "websocket": false,
    "withAdminUi": true
  }
}
Entity configuration(s) entityName.json files generated in the .jhipster directory
{
  "applications": "*",
  "changelogDate": "20230306232343",
  "dto": "no",
  "embedded": false,
  "entityTableName": "p",
  "fields": [
    {
      "fieldName": "note",
      "fieldType": "String"
    }
  ],
  "fluentMethods": true,
  "jpaMetamodelFiltering": false,
  "name": "P",
  "pagination": "no",
  "readOnly": false,
  "relationships": [
    {
      "otherEntityField": "symbol",
      "otherEntityName": "w",
      "relationshipName": "w",
      "relationshipType": "many-to-one"
    }
  ],
  "service": "no"
}

{
  "applications": "*",
  "changelogDate": "20230306232344",
  "dto": "no",
  "embedded": false,
  "entityTableName": "s",
  "fields": [
    {
      "fieldName": "symbol",
      "fieldType": "String",
      "fieldValidateRules": ["pattern", "required"],
      "fieldValidateRulesPattern": "^[a-zA-Z0-9.]{1,8}$"
    }
  ],
  "fluentMethods": true,
  "jpaMetamodelFiltering": false,
  "name": "S",
  "pagination": "no",
  "readOnly": false,
  "relationships": [],
  "service": "no"
}

{
  "applications": "*",
  "changelogDate": "20230306232345",
  "dto": "no",
  "embedded": false,
  "entityTableName": "w",
  "fields": [
    {
      "fieldName": "symbol",
      "fieldType": "String"
    }
  ],
  "fluentMethods": true,
  "jpaMetamodelFiltering": false,
  "name": "W",
  "pagination": "no",
  "readOnly": false,
  "relationships": [],
  "service": "no"
}
Browsers and Operating System
OmarHawk commented 1 year ago

Can you try with latest main branch? In #20536 I fixed a similar issue... and in #18751 I changed the way how relationships are re-generated when changing things in there..

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for too long without any activity. Due to the moving nature of jhipster generated application, bugs can become invalid. If this issue still applies please comment otherwise it will be closed in 7 days