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

Embedded OneToOne relationship generation fails #18017

Closed tchlyah closed 2 years ago

tchlyah commented 2 years ago
Overview of the issue

It seems that there is a regression in latest version of JHipster (7.7.0): If the other side of a OneToOne relationship is embedded, the generation fails with the following error:

Error running generator app: TypeError: Cannot read properties of undefined (reading 'name')
TypeError: Cannot read properties of undefined (reading 'name')
    at /Users/tayebchlyah/Projects/jhipster/projects/generator-jhipster/generators/entity/index.js:860:78
    at Array.forEach (<anonymous>)
    at EntityGenerator.processEagerLoadRelationships (/Users/tayebchlyah/Projects/jhipster/projects/generator-jhipster/generators/entity/index.js:853:36)
    at Object.<anonymous> (/Users/tayebchlyah/Projects/jhipster/projects/generator-jhipster/node_modules/yeoman-generator/lib/index.js:1097:23)
    at /Users/tayebchlyah/Projects/jhipster/projects/generator-jhipster/node_modules/run-async/index.js:49:25
    at new Promise (<anonymous>)
    at /Users/tayebchlyah/Projects/jhipster/projects/generator-jhipster/node_modules/run-async/index.js:26:19
    at /Users/tayebchlyah/Projects/jhipster/projects/generator-jhipster/node_modules/yeoman-generator/lib/index.js:1098:9
    at new Promise (<anonymous>)
    at EntityGenerator.executeTask (/Users/tayebchlyah/Projects/jhipster/projects/generator-jhipster/node_modules/yeoman-generator/lib/index.js:1069:12)
    at runLoop.add.once (/Users/tayebchlyah/Projects/jhipster/projects/generator-jhipster/node_modules/yeoman-generator/lib/index.js:1049:14)
    at Immediate.<anonymous> (/Users/tayebchlyah/Projects/jhipster/projects/generator-jhipster/node_modules/grouped-queue/lib/subqueue.js:48:34)
    at processImmediate (node:internal/timers:466:21)
Reproduce the error

Use the JDL below.

Suggest a Fix

A simple fix is to add a check relationship.otherEntity.primaryKey != null to https://github.com/jhipster/generator-jhipster/blob/b3fca5e60288c9a5a8d8e84dfee314a20fc97b45/generators/entity/index.js#L860-L860

But since this code didn't change on version 7.7.0 (there was some updates after in the main branche but the issue is the same), I think it is coming from an other change that I couldn't find.

JHipster Version(s)

7.7.0

JHipster configuration
JDL definitions
entity Entity1 {}

@embedded
entity Entity2 {}

relationship OneToOne {
  Entity1 to Entity2
}
tchlyah commented 2 years ago

@mshima can you please take a look ? It's kind of urgent since I can't use the new collections and scope introduced by JHipster 7.7.0! Thanks

mshima commented 2 years ago

I confirm. I prefer testing embedded instead of primaryKey. As workaround add @EagerLoad annotation to the relationship, it should not change anything using couchbase.