Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jHipster 6.1.2: Wrong Angular code for one-to-one relationship breaks create/update form #9991

1 task done
ksilz opened this issue Jun 25, 2019 · 3 comments
1 task done


Copy link

@ksilz ksilz commented Jun 25, 2019

Overview of the issue

For my Angular / H2 monolith, jHipster generates the wrong create / update class for my Shipment entity which has a one-to-one relationship with ShoppingOrder. It wants to load a non-existent shopping order instead of loading all orders when creating a new shipment.

Here is the stacktrace:

2019-06-25 23:47:56.129 DEBUG 84738 --- [ XNIO-1 task-54] c.b.t.j.aop.logging.LoggingAspect        : Exit: with result = [ShoppingOrderDTO{id=1, name='Ergonomic transmitter', totalAmount=36778.0, ordered='2019-06-25T11:08:05+02:00[Europe/Berlin]', buyer=2, buyer='anonymoususer'}, ShoppingOrderDTO{id=2, name='withdrawal Solomon Islands Licensed', totalAmount=83530.0, ordered='2019-06-25T18:48:17+02:00[Europe/Berlin]', buyer=1, buyer='system'}, ShoppingOrderDTO{id=3, name='magenta Refined Rubber Gloves', totalAmount=67756.0, ordered='2019-06-25T17:08:10+02:00[Europe/Berlin]', buyer=1, buyer='system'}, ShoppingOrderDTO{id=4, name='Buckinghamshire Future-proofed deposit', totalAmount=17436.0, ordered='2019-06-24T23:50:58+02:00[Europe/Berlin]', buyer=2, buyer='anonymoususer'}, ShoppingOrderDTO{id=5, name='synthesize Creative', totalAmount=13752.0, ordered='2019-06-25T06:12:20+02:00[Europe/Berlin]', buyer=1, buyer='system'}, ShoppingOrderDTO{id=6, name='Concrete Global SMS', totalAmount=25794.0, ordered='2019-06-25T16:56:12+02:00[Europe/Berlin]', buyer=2, buyer='anonymoususer'}, ShoppingOrderDTO{id=7, name='parsing', totalAmount=55520.0, ordered='2019-06-25T10:01:22+02:00[Europe/Berlin]', buyer=2, buyer='anonymoususer'}, ShoppingOrderDTO{id=8, name='Vision-oriented', totalAmount=9310.0, ordered='2019-06-24T23:15:07+02:00[Europe/Berlin]', buyer=2, buyer='anonymoususer'}, ShoppingOrderDTO{id=9, name='Human deposit', totalAmount=33902.0, ordered='2019-06-25T15:43:45+02:00[Europe/Berlin]', buyer=1, buyer='system'}, ShoppingOrderDTO{id=10, name='bus Internal AI', totalAmount=77987.0, ordered='2019-06-25T01:06:56+02:00[Europe/Berlin]', buyer=2, buyer='anonymoususer'}]
2019-06-25 23:47:56.158  WARN 84738 --- [ XNIO-1 task-56] o.z.problem.spring.common.AdviceTraits   : Bad Request: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "undefined"
2019-06-25 23:47:56.159  WARN 84738 --- [ XNIO-1 task-56] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "undefined"]

I added log statements in the same Angular class (lines 57 and 60), so you can see in the browser dev tools console how the else branch is reached:

ShipmentUpdateComponent.ngOnInit.shoppingOrderService.query: orderId: undefined
Motivation for or Use Case

I have a valid JDL file that jHipster imports without reporting an error. However, the generated front-end code doesn't work for one entity.

Reproduce the error
  • Create a new jHipster project with Java 11 by importing my JDL file.
  • Run ./gradlew to start the application.
  • The application will probably fail to load the fake data for the shipment table.
  • Log into the application.
  • Go to the Entities - Shipment menu.
  • Click the Create a new Shipment button.
  • Witness the Bad request. error message appearing and the empty Order drop-own.
Related issues

#9990: For that very same entity, JHipster generates the wrong fake data.

Suggest a Fix

In line 56 of shipment-update.component.ts, take away one of the two ! in front of this.editForm.get('orderId').value.

JHipster Version(s)

JHipster 6.1.2, Java 11

JHipster configuration
my-simple-shop@0.0.0 /Users/karsten/workspaces/me/services/better-projects-faster/bug-reports/jhipster-6.1.2-java-11-test
└── generator-jhipster@6.1.2 

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
  "generator-jhipster": {
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "enableHibernateCache": true,
    "enableSwaggerCodegen": false,
    "enableTranslation": true,
    "jhiPrefix": "bpf",
    "languages": ["en", "de"],
    "messageBroker": false,
    "nativeLanguage": "en",
    "packageName": "com.betterprojectsfaster.tutorial.jhipsterdocker",
    "packageFolder": "com/betterprojectsfaster/tutorial/jhipsterdocker",
    "prodDatabaseType": "postgresql",
    "searchEngine": false,
    "serviceDiscoveryType": false,
    "skipClient": false,
    "skipServer": false,
    "testFrameworks": ["protractor"],
    "websocket": "spring-websocket",
    "baseName": "my_simple_shop",
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "buildTool": "gradle",
    "cacheProvider": "ehcache",
    "clientFramework": "angularX",
    "useSass": true,
    "clientPackageManager": "npm",
    "jhipsterVersion": "6.1.2",
    "skipUserManagement": false,
    "serverPort": "8080",
    "jwtSecretKey": "bXktc2VjcmV0LXRva2VuLXRvLWNoYW5nZS1pbi1wcm9kdWN0aW9uLWFuZC10by1rZWVwLWluLWEtc2VjdXJlLXBsYWNl",
    "clientTheme": "none",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": []
  "entities": ["Product", "Address", "ShoppingOrder", "ProductOrder", "Shipment"]
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 ZonedDateTime
entity ProductOrder {
  amount Integer required min(0) max(5)
entity Shipment {
  shippedAt ZonedDateTime required
enum ProductCategory {

relationship OneToOne {
  Shipment{order(name) required} to ShoppingOrder{shipment required}
relationship OneToMany {
  Product{order required} to ProductOrder{product(name) required},
  ShoppingOrder{orders required} to ProductOrder{overallOrder(name)}
relationship ManyToOne {
  Address{user(login) required} to User,
  ShoppingOrder{buyer(login) required} to User,
  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 serviceClass

Environment and Tools

openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.3+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.3+7, mixed mode)

git version 2.22.0

node: v10.15.3

npm: 6.9.0

yeoman: 2.0.6

Docker version 18.09.2, build 6247962

docker-compose version 1.23.2, build 1110ad01

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


    "name": "Shipment",
    "fields": [
            "fieldName": "shippedAt",
            "fieldType": "ZonedDateTime",
            "fieldValidateRules": [
    "relationships": [
            "relationshipType": "one-to-one",
            "otherEntityName": "shoppingOrder",
            "otherEntityRelationshipName": "shipment",
            "relationshipValidateRules": "required",
            "relationshipName": "order",
            "otherEntityField": "name",
            "ownerSide": true
            "relationshipType": "many-to-one",
            "otherEntityName": "user",
            "otherEntityRelationshipName": "shipment",
            "relationshipValidateRules": "required",
            "relationshipName": "shippedBy",
            "otherEntityField": "login"
    "changelogDate": "20190625202518",
    "entityTableName": "shipment",
    "dto": "mapstruct",
    "pagination": "no",
    "service": "serviceClass",
    "jpaMetamodelFiltering": false,
    "fluentMethods": true,
    "clientRootFolder": "",
    "applications": [
Browsers and Operating System

macOS Mojave 10.14.4, Safari

  • Checking this box is mandatory (this is just to show you read everything)
Copy link

@pmverma pmverma commented Jul 14, 2019

Just a note: I was able to reproduce this error while doing PR #10092 which fixes #9990.

Copy link

@pmverma pmverma commented Jul 14, 2019

I just notice that PR #10030 is fixing this same issue.

Copy link

@pmverma pmverma commented Jul 15, 2019

Closing this since #10030 is merged.

@pmverma pmverma closed this as completed Jul 15, 2019
@pascalgrimaud pascalgrimaud added this to the 6.2.0 milestone Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

3 participants