Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

microservices - JHipster 7.1.0: Failed to use jdl-import, throws Error looking for otherEntity User at

Im using java Openjdk 11.0.11, JHipster 7.1.0 and node v14.17.3 Im creating a simple microservice (one backend and one gateway) but JHipster fails to create using the jdl command (jdl-import), it throws

Error: Error looking for otherEntity User at Tag,Product,Blog,Post
    at /Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/generators/entity/index.js:560:19
    at Array.forEach (<anonymous>)
    at EntityGenerator.loadRelationships (/Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/generators/entity/index.js:556:36)
    at Object.<anonymous> (/Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/lib/index.js:1024:25)
    at /Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/node_modules/run-async/index.js:49:25
    at new Promise (<anonymous>)
    at /Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/node_modules/run-async/index.js:26:19
    at runLoop.add.once.once (/Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/lib/index.js:1025:11)
    at Immediate.<anonymous> (/Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/node_modules/grouped-queue/lib/subqueue.js:48:34)
    at processImmediate (internal/timers.js:464:21)
INFO! Generator app child process exited with code 1
ERROR! Error executing app --reproducible --no-force --with-entities --no-dry-run --no-whitespace --no-bail --no-skip-regenerate --no-skip-yo-resolve --from-jdl --no-skip-cache --no-skip-install --no-force-install --no-ask-answered --no-defaults --no-skip-git
Error: Error executing app --reproducible --no-force --with-entities --no-dry-run --no-whitespace --no-bail --no-skip-regenerate --no-skip-yo-resolve --from-jdl --no-skip-cache --no-skip-install --no-force-install --no-ask-answered --no-defaults --no-skip-git
    at ChildProcess.<anonymous> (/Users/carestra/.nvm/versions/node/v14.17.3/lib/node_modules/generator-jhipster/cli/import-jdl.js:194:16)
    at ChildProcess.emit (events.js:375:28)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The error occurs because you're using JWT authentication type and not OAuth2.

For OAuth2, there is a mechanism in the microservice to extract user data from token and save it to the service's database.

Unfortunately, I could not find any doc about this so I read the code at https://github.com/jhipster/generator-jhipster/blob/main/utils/entity.js where the test to determine whether to activate this user snapshot is:

  entityWithConfig.saveUserSnapshot =
    entityWithConfig.applicationType === MICROSERVICE &&
    entityWithConfig.authenticationType === OAUTH2 &&
    hasBuiltInUserField &&
    entityWithConfig.dto === NO_MAPPER;

You can see that there is also a condition about not using a DTO.

This mechanism has some restrictions though because the user's data is updated only when service API gets called, you can imagine cases where a user has been updated in gateway and a background job is running in service that will use a stale version of the user.

For JWT, this has not been implemented because the token does not contain enough data about user, it contains only the login and roles.

So with JWT, can you store in Blog only the ID (or login) of a User and not define a relationship with User entity because it exists only in gateway database.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...