Search code examples
jhipsterjdl

JHipster jdl import entity generator failing to create relationship between entities


I am generating entities using JHipster JDL.

INFO! Using JHipster version installed locally in current project's node_modules 6.10.1

JDL used to generate entities

entity Products{
    name String required
    brand String required
    quantity String required
    messurement String
    description String
}

entity ProductTypes{
    productType String required
    description String
}

relationship ManyToOne{
    Products{productType} to ProductTypes
}

// Set pagination options
paginate all with pagination

// Use Data Transfert Objects (DTO)
dto * with mapstruct

// Set service options to all except few
service all with serviceImpl

// Set an angular suffix
// angularSuffix * with mySuffix

Used below command to run JDL and ran successfully without any errors

$jhipster import-jdl jdl/jhipster-jdl.jdl

Output Summary:

 DONE  Compiled successfully in 23047ms                                              4:15:42 PM

   489 modules
INFO! Congratulations, JHipster execution is complete!

Now when try to start application, getting below error

        ██╗ ██╗   ██╗ ████████╗ ███████╗   ██████╗ ████████╗ ████████╗ ███████╗
        ██║ ██║   ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
        ██║ ████████║    ██║    ███████╔╝ ╚█████╗     ██║    ██████╗   ███████╔╝
  ██╗   ██║ ██╔═══██║    ██║    ██╔════╝   ╚═══██╗    ██║    ██╔═══╝   ██╔══██║
  ╚██████╔╝ ██║   ██║ ████████╗ ██║       ██████╔╝    ██║    ████████╗ ██║  ╚██╗
   ╚═════╝  ╚═╝   ╚═╝ ╚═══════╝ ╚═╝       ╚═════╝     ╚═╝    ╚═══════╝ ╚═╝   ╚═╝

:: JHipster 🤓  :: Running Spring Boot 2.2.7.RELEASE ::
:: https://www.jhipster.tech ::

2020-10-24 16:17:09.493  WARN 17105 --- [  restartedMain] o.s.boot.StartupInfoLogger               : InetAddress.getLocalHost().getHostName() took 5001 milliseconds to respond. Please verify your network configuration (macOS machines may need to add entries to /etc/hosts).

***

2020-10-24 16:17:17.546 DEBUG 17105 --- [  restartedMain] c.m.l.config.LiquibaseConfiguration      : Configuring Liquibase
2020-10-24 16:17:17.551  WARN 17105 --- [lication-task-1] i.g.j.c.liquibase.AsyncSpringLiquibase   : Starting Liquibase asynchronously, your database might not be ready at startup!
2020-10-24 16:17:18.891 DEBUG 17105 --- [  restartedMain] c.m.l.security.jwt.TokenProvider         : Using a Base64-encoded JWT secret key
2020-10-24 16:17:20.312 ERROR 17105 --- [lication-task-1] liquibase.changelog.ChangeSet            : Change Set config/liquibase/changelog/20201008101647_added_entity_constraints_Products.xml::20201008101647-2::jhipster failed.  Error: Column "PRODUCT_TYPE_ID" not found; SQL statement:
ALTER TABLE PUBLIC.products ADD CONSTRAINT fk_products_product_type_id FOREIGN KEY (product_type_id) REFERENCES PUBLIC.product_types (id) [42122-200] [Failed SQL: (42122) ALTER TABLE PUBLIC.products ADD CONSTRAINT fk_products_product_type_id FOREIGN KEY (product_type_id) REFERENCES PUBLIC.product_types (id)]
2020-10-24 16:17:20.320 ERROR 17105 --- [lication-task-1] i.g.j.c.liquibase.AsyncSpringLiquibase   : Liquibase could not start correctly, your database is NOT ready: Migration failed for change set config/liquibase/changelog/20201008101647_added_entity_constraints_Products.xml::20201008101647-2::jhipster:
     Reason: liquibase.exception.DatabaseException: Column "PRODUCT_TYPE_ID" not found; SQL statement:
ALTER TABLE PUBLIC.products ADD CONSTRAINT fk_products_product_type_id FOREIGN KEY (product_type_id) REFERENCES PUBLIC.product_types (id) [42122-200] [Failed SQL: (42122) ALTER TABLE PUBLIC.products ADD CONSTRAINT fk_products_product_type_id FOREIGN KEY (product_type_id) REFERENCES PUBLIC.product_types (id)]

liquibase.exception.MigrationFailedException: Migration failed for change set config/liquibase/changelog/20201008101647_added_entity_constraints_Products.xml::20201008101647-2::jhipster:
     Reason: liquibase.exception.DatabaseException: Column "PRODUCT_TYPE_ID" not found; SQL statement:
ALTER TABLE PUBLIC.products ADD CONSTRAINT fk_products_product_type_id FOREIGN KEY (product_type_id) REFERENCES PUBLIC.product_types (id) [42122-200] [Failed SQL: (42122) ALTER TABLE PUBLIC.products ADD CONSTRAINT fk_products_product_type_id FOREIGN KEY (product_type_id) REFERENCES PUBLIC.product_types (id)]
    at liquibase.changelog.ChangeSet.execute(ChangeSet.java:646)
    at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:53)
    at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:83)
    at liquibase.Liquibase.update(Liquibase.java:202)
    at liquibase.Liquibase.update(Liquibase.java:179)
    at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:366)
    at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:314)
    at org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase.afterPropertiesSet(DataSourceClosingSpringLiquibase.java:46)
    at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.initDb(AsyncSpringLiquibase.java:118)
    at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.lambda$afterPropertiesSet$0(AsyncSpringLiquibase.java:93)
    at io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor.lambda$createWrappedRunnable$1(ExceptionHandlingAsyncTaskExecutor.java:78)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: liquibase.exception.DatabaseException: Column "PRODUCT_TYPE_ID" not found; SQL statement:
ALTER TABLE PUBLIC.products ADD CONSTRAINT fk_products_product_type_id FOREIGN KEY (product_type_id) REFERENCES PUBLIC.product_types (id) [42122-200] [Failed SQL: (42122) ALTER TABLE PUBLIC.products ADD CONSTRAINT fk_products_product_type_id FOREIGN KEY (product_type_id) REFERENCES PUBLIC.product_types (id)]
    at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:402)
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:59)
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:131)
    at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1276)
    at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1258)
    at liquibase.changelog.ChangeSet.execute(ChangeSet.java:609)
    ... 13 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "PRODUCT_TYPE_ID" not found; SQL statement:
ALTER TABLE PUBLIC.products ADD CONSTRAINT fk_products_product_type_id FOREIGN KEY (product_type_id) REFERENCES PUBLIC.product_types (id) [42122-200]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:453)
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
    at org.h2.message.DbException.get(DbException.java:205)
    at org.h2.message.DbException.get(DbException.java:181)
    at org.h2.table.Table.getColumn(Table.java:703)
    at org.h2.table.IndexColumn.mapColumns(IndexColumn.java:115)
    at org.h2.command.ddl.AlterTableAddConstraint.tryUpdate(AlterTableAddConstraint.java:216)
    at org.h2.command.ddl.AlterTableAddConstraint.update(AlterTableAddConstraint.java:78)
    at org.h2.command.CommandContainer.update(CommandContainer.java:198)
    at org.h2.command.Command.executeUpdate(Command.java:251)
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:228)
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:201)
    at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95)
    at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
    at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:398)
    ... 18 common frames omitted

2020-10-24 16:17:20.750 DEBUG 17105 --- [  restartedMain] c.m.l.config.DatabaseConfiguration       : H2 database is available on port 18080
2020-10-24 16:17:31.364 DEBUG 17105 --- [  restartedMain] i.g.j.c.apidoc.SwaggerAutoConfiguration  : Starting Swagger
2020-10-24 16:17:31.372 DEBUG 17105 --- [  restartedMain] i.g.j.c.apidoc.SwaggerAutoConfiguration  : Started Swagger in 7 ms
2020-10-24 16:17:37.031  INFO 17105 --- [  restartedMain] com.mv.localshops.BaseapplicationApp     : Started BaseapplicationApp in 43.019 seconds (JVM running for 43.521)
2020-10-24 16:17:42.040  INFO 17105 --- [  restartedMain] com.mv.localshops.BaseapplicationApp     : 
----------------------------------------------------------
    Application 'baseapplication' is running! Access URLs:
    Local:      http://localhost:8080/
    External:   http://192.168.1.11:8080/
    Profile(s):     [dev, swagger]
----------------------------------------------------------

Can you please help me to understand why this error is thrown. Am I using JHipster entity generator in correct way?

Any help is appreciated.


Solution

  • Issue got resolved after upgrading JHipster from 6.10.1 to 6.10.4

    Used below command for upgrade and worked like charm

    jhipster upgrade
    

    Two things I followed:

    1. I had to delete and reinstall node module using
    rm -rf node_modules 
    npm install
    
    1. While upgrade it asked one question below. I just clicked entered and it took default option I guess
    git rev-parse -q --abbrev-ref HEAD
    master
    ? Unify blueprints configurations?
    
    
    git rev-parse -q --abbrev-ref HEAD
    master
    ? Unify blueprints configurations? Yes
         info Skipping config upgrade, config generated with jhipster version: 6.10.1
    git rev-parse -q --verify jhipster_upgrade
    git checkout --orphan jhipster_upgrade
    Switched to a new branch 'jhipster_upgrade'
    ✔ Created branch jhipster_upgrade