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.48k stars 4.02k forks source link

JHipster fails to create fake data file for one entity #19916

Closed ksilz closed 1 year ago

ksilz commented 1 year ago
Overview of the issue

I have a JHipster tutorial where I import a JDL file with the application configuration and entities. With JHipster 7.9.3, the application creates a fake data file without any records for my Product entity. So the start-up fails because Liquibase can't create a foreign key relationship to that empty product table.

Motivation for or Use Case

The generated application doesn't start correctly.

Reproduce the error
  1. Create a new project folder.

  2. Copy the attached simple-shop-app.txt to that folder.

  3. Change into that folder.

  4. Import it with jhipster import-jdl simple-shop-app.txt

  5. Run the generated application with mvnw/./mvnw.

  6. You'll see an error during start-up like this:

2022-10-03T09:52:19.581+01:00 ERROR 55275 --- [ple-shop-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/20221003084643_added_entity_constraints_ProductOrder.xml::20221003084643-2::jhipster:_     Reason: liquibase.exception.DatabaseException: Referential integrity constraint violation: "FK_PRODUCT_ORDER__PRODUCT_ID: PUBLIC.PRODUCT_ORDER FOREIGN KEY(PRODUCT_ID) REFERENCES PUBLIC.PRODUCT(ID)"; SQL statement:_ALTER TABLE PUBLIC.product_order ADD CONSTRAINT fk_product_order__product_id FOREIGN KEY (product_id) REFERENCES PUBLIC.product (id) [23506-214] [Failed SQL: (23506) ALTER TABLE PUBLIC.product_order ADD CONSTRAINT fk_product_order__product_id FOREIGN KEY (product_id) REFERENCES PUBLIC.product (id)]
  1. Open http://localhost:8080/ in your web browser.
  2. Sign in as user/user.
  3. Check out the "Entities" menu: "Address", "Shopping Order", and "Shipments" have data, while "Product" and "Product Orders" do not.
  4. Look at the src/main/resources/cocat src/main/resources/config/liquibase/fake-data/product.csv file. It's empty:
jhipster-test-3 [main] % cat src/main/resources/config/liquibase/fake-data/product.csv
id;name;price;description;picture;picture_content_type;specification;specification_content_type;category;inventory
jhipster-test-3 [main] %
Related issues

No

Suggest a Fix

A workaround:

  1. Stop the application.
  2. Copy the attached product.csv into src/main/resources/config/liquibase/fake-data
  3. Start the application again.
  4. The application now starts without errors.
  5. Open http://localhost:8080/ in your web browser.
  6. Sign in as user/user.
  7. Check out the "Entities" menu: "Product" and "Product Orders" now have data.
JHipster Version(s)
my-simple-shop@0.0.1-SNAPSHOT /Users/karsten/workspaces/me/services/better-projects-faster/test/jhipster-test-3
└── generator-jhipster@7.9.3

It worked with 7.3.1.

JHipster configuration

jhipster info

INFO! Switching to JHipster installed locally in current project's node repository (node_modules)
(node:58995) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./lib/util/" in the "exports" field module resolution of the package at /Users/karsten/workspaces/me/services/better-projects-faster/test/jhipster-test-3/node_modules/yeoman-environment/package.json.
Update this package.json to use a subpath pattern like "./lib/util/*".
(Use `node --trace-deprecation ...` to show where the warning was created)
Welcome to JHipster v7.9.3

Welcome to the JHipster Information Sub-Generator

##### **JHipster Version(s)**

my-simple-shop@0.0.1-SNAPSHOT /Users/karsten/workspaces/me/services/better-projects-faster/test/jhipster-test-3
└── generator-jhipster@7.9.3
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "applicationIndex": 0,
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "baseName": "my_simple_shop",
    "blueprints": [],
    "buildTool": "maven",
    "cacheProvider": "ehcache",
    "clientFramework": "react",
    "clientPackageManager": "npm",
    "clientTheme": "litera",
    "clientThemeVariant": "primary",
    "creationTimestamp": 1664786563180,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "devServerPort": 9060,
    "dtoSuffix": "DTO",
    "enableGradleEnterprise": false,
    "enableHibernateCache": true,
    "enableSwaggerCodegen": false,
    "enableTranslation": true,
    "entities": ["Product", "Address", "ShoppingOrder", "ProductOrder", "Shipment"],
    "entitySuffix": "",
    "gradleEnterpriseHost": "",
    "jhiPrefix": "bpf",
    "jhipsterVersion": "7.9.3",
    "jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "languages": ["en", "de", "ru"],
    "lastLiquibaseTimestamp": 1664786863000,
    "messageBroker": false,
    "nativeLanguage": "en",
    "otherModules": [],
    "packageFolder": "com/betterprojectsfaster/tutorial/jhipsterdocker",
    "packageName": "com.betterprojectsfaster.tutorial.jhipsterdocker",
    "pages": [],
    "prodDatabaseType": "postgresql",
    "reactive": false,
    "searchEngine": false,
    "serverPort": "8080",
    "serviceDiscoveryType": false,
    "skipCheckLengthOfIdentifier": false,
    "skipClient": false,
    "skipFakeData": false,
    "skipServer": false,
    "skipUserManagement": false,
    "testFrameworks": ["cypress"],
    "websocket": "spring-websocket",
    "withAdminUi": true
  }
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Product {
  name String required unique minlength(2) maxlength(90)
  price Float required min(0)
  description TextBlob required
  picture ImageBlob required
  specification AnyBlob
  category ProductCategory
  inventory Integer required min(0)
}
entity Address {
  addressLine1 String required minlength(2) maxlength(80)
  addressLine2 String minlength(2) maxlength(80)
  city String minlength(2) maxlength(80)
  postalCode String minlength(5) maxlength(5)
}
entity ShoppingOrder {
  name String required unique minlength(2) maxlength(90)
  totalAmount Float min(0)
  ordered LocalDate
}
entity ProductOrder {
  amount Integer required min(0) max(5)
}
entity Shipment {
  shippedAt LocalDate required
}
enum ProductCategory {
  Laptop,
  Desktop,
  Phone,
  Tablet,
  Accessory
}

relationship OneToOne {
  Shipment{order(name) required} to ShoppingOrder{shipment(shippedAt)}
}
relationship OneToMany {
  ShoppingOrder{orders} to ProductOrder{overallOrder(name) required}
}
relationship ManyToOne {
  Address{user(login) required} to User
  ShoppingOrder{buyer(login) required} to User
  ProductOrder{product(name) required} to Product
  ProductOrder{buyer(login) required} to User
  Shipment{shippedBy(login) required} to User
}

dto Product, Address, ShoppingOrder, ProductOrder, Shipment with mapstruct
service Product, Address, ShoppingOrder, ProductOrder, Shipment with serviceImpl

Environment and Tools

openjdk version "17.0.4.1" 2022-08-12 OpenJDK Runtime Environment Temurin-17.0.4.1+1 (build 17.0.4.1+1) OpenJDK 64-Bit Server VM Temurin-17.0.4.1+1 (build 17.0.4.1+1, mixed mode)

git version 2.37.3

node: v16.17.1

npm: 8.15.0

Docker version 20.10.17, build 100c701

docker-compose version 1.29.2, build 5becea4c

No change to package.json was detected. No package manager install will be executed. Congratulations, JHipster execution is complete! Sponsored with ❤️ by @oktadev.

Entity configuration(s) entityName.json files generated in the .jhipster directory

See Entities.zip.

Browsers and Operating System
dwarakaprasad commented 1 year ago

This is a bug in table_entity.csv.ejs. When the field type is 'byte[]' and not Text, a special _content_type column is being added, but,

  1. It is not updated properly during the line creation
  2. This causes the lines column count to be not equal to header count causing nothing to be added and hence empty csv file.

I will create a pr shortly for this issue.