Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

Unable to generate an application with a custom User entity that has a relationship to other entities because skipUserManagement and --skip-user-management are being ignored #476

Closed
1 task done
deftdawg opened this issue Jul 17, 2020 · 5 comments

Comments

@deftdawg
Copy link

Overview of the issue

Unable to generate an application with a custom User entity that has a relationship to other entities because skipUserManagement and --skip-user-management are being ignored.

Full stacktrace

hipster import-jdl ../test.jdl --skip-user-management --skip-git --ignore-client
INFO! Using JHipster version installed locally in current project's node_modules
INFO! Executing import-jdl ../test.jdl
INFO! Found .yo-rc.json on path. This is an existing app
INFO! The JDL is being parsed.
warn: In the One-to-Many relationship from User to LogEntry, only bidirectionality is supported for a One-to-Many association. The other side will be automatically added.
Error: Relationships from the User entity is not supported in the declaration between 'User' and 'LogEntry'. You can have this by using the 'skipUserManagement' option.
Error while parsing applications and entities from the JDL Error: Relationships from the User entity is not supported in the declaration between 'User' and 'LogEntry'. You can have this by using the 'skipUserManagement' option.
Error: Relationships from the User entity is not supported in the declaration between 'User' and 'LogEntry'. You can have this by using the 'skipUserManagement' option.
    at checkForForbiddenUseOfUserAsSource (/Users/dd/source/test/test2/node_modules/jhipster-core/lib/validators/relationship_validator.js:89:11)
    at checkForInvalidUseOfTheUserEntity (/Users/dd/source/test/test2/node_modules/jhipster-core/lib/validators/relationship_validator.js:83:3)
    at RelationshipValidator.validate (/Users/dd/source/test/test2/node_modules/jhipster-core/lib/validators/relationship_validator.js:37:5)
    at /Users/dd/source/test/test2/node_modules/jhipster-core/lib/validators/business_error_checker.js:158:17
    at /Users/dd/source/test/test2/node_modules/jhipster-core/lib/core/jdl_object.js:202:7
    at /Users/dd/source/test/test2/node_modules/jhipster-core/lib/core/jdl_relationships.js:90:7
    at Array.forEach (<anonymous>)
    at JDLRelationships.forEach (/Users/dd/source/test/test2/node_modules/jhipster-core/lib/core/jdl_relationships.js:89:20)
    at JDLObject.forEachRelationship (/Users/dd/source/test/test2/node_modules/jhipster-core/lib/core/jdl_object.js:201:24)
    at BusinessErrorChecker.checkForRelationshipErrors (/Users/dd/source/test/test2/node_modules/jhipster-core/lib/validators/business_error_checker.js:157:20)
Error during import-jdl: Relationships from the User entity is not supported in the declaration between 'User' and 'LogEntry'. You can have this by using the 'skipUserManagement' option.
Error: Relationships from the User entity is not supported in the declaration between 'User' and 'LogEntry'. You can have this by using the 'skipUserManagement' option.
    at checkForForbiddenUseOfUserAsSource (/Users/dd/source/test/test2/node_modules/jhipster-core/lib/validators/relationship_validator.js:89:11)
    at checkForInvalidUseOfTheUserEntity (/Users/dd/source/test/test2/node_modules/jhipster-core/lib/validators/relationship_validator.js:83:3)
    at RelationshipValidator.validate (/Users/dd/source/test/test2/node_modules/jhipster-core/lib/validators/relationship_validator.js:37:5)
    at /Users/dd/source/test/test2/node_modules/jhipster-core/lib/validators/business_error_checker.js:158:17
    at /Users/dd/source/test/test2/node_modules/jhipster-core/lib/core/jdl_object.js:202:7
    at /Users/dd/source/test/test2/node_modules/jhipster-core/lib/core/jdl_relationships.js:90:7
    at Array.forEach (<anonymous>)
    at JDLRelationships.forEach (/Users/dd/source/test/test2/node_modules/jhipster-core/lib/core/jdl_relationships.js:89:20)
    at JDLObject.forEachRelationship (/Users/dd/source/test/test2/node_modules/jhipster-core/lib/core/jdl_object.js:201:24)
    at BusinessErrorChecker.checkForRelationshipErrors (/Users/dd/source/test/test2/node_modules/jhipster-core/lib/validators/business_error_checker.js:157:20)
Error: Error during import-jdl: Relationships from the User entity is not supported in the declaration between 'User' and 'LogEntry'. You can have this by using the 'skipUserManagement' option.
    at module.exports (/Users/dd/source/test/test2/node_modules/generator-jhipster/cli/import-jdl.js:428:31)
    at /Users/dd/source/test/test2/node_modules/generator-jhipster/cli/jdl.js:93:51
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
Motivation for or Use Case

If I remove the OneToMany relationship JHipster will generate the classes, however it's kind of a useless that a User entity cannot have relationships with any other entities. This is also unexpected because the JDL has no problems rendering in JDL-Studio.

Reproduce the error

Here is the command:

jhipster import-jdl ../test.jdl --skip-user-management --skip-git --ignore-client

Here is the test.jdl file:

// skip-user-management

application {
    config {
        baseName testmicroservice
        applicationType microservice
        serviceDiscoveryType consul
        serverPort 9001
        skipUserManagement true
    }
    entities *
}

entity User { 
    name String required
    username String required
    email String required pattern(/^[^@\s]+@[^@\s]+\.[^@\s]+$/) 
}

entity LogEntry {
    eventTimestamp Instant required
    eventObject String 
    eventDetails String
}

/**
 * One to many relationship.
 */
relationship OneToMany {
    User to LogEntry{username}
}
Related issues
Suggest a Fix
JHipster Version(s)
JHipster configuration

jhipster info
INFO! Using JHipster version installed locally in current project's node_modules
INFO! Executing jhipster:info
Welcome to the JHipster Information Sub-Generator

JHipster Version(s)
testmicroservice@0.0.0 /Users/dd/source/test/test2
└── generator-jhipster@6.10.1 

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "authenticationType": "jwt",
    "cacheProvider": "hazelcast",
    "serverPort": "9001",
    "serviceDiscoveryType": "consul",
    "skipUserManagement": true,
    "baseName": "testmicroservice",
    "buildTool": "maven",
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "enableHibernateCache": true,
    "enableSwaggerCodegen": false,
    "enableTranslation": true,
    "jhiPrefix": "jhi",
    "languages": ["en", "fr"],
    "messageBroker": false,
    "nativeLanguage": "en",
    "prodDatabaseType": "mysql",
    "searchEngine": false,
    "skipClient": true,
    "testFrameworks": [],
    "websocket": false,
    "applicationType": "microservice",
    "jhipsterVersion": "6.10.1",
    "creationTimestamp": 1595026560761,
    "packageFolder": "com/mycompany/myapp",
    "packageName": "com.mycompany.myapp",
    "clientPackageManager": "npm",
    "jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "embeddableLaunchScript": false,
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": [],
    "blueprints": []
  },
  "entities": ["User", "LogEntry"]
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity LogEntry {
  eventTimestamp Instant required,
  eventObject String,
  eventDetails String
}

Environment and Tools

openjdk version "14.0.1" 2020-04-14
OpenJDK Runtime Environment (build 14.0.1+14)
OpenJDK 64-Bit Server VM (build 14.0.1+14, mixed mode, sharing)

git version 2.27.0

node: v14.5.0

npm: 6.14.5

Docker version 19.03.12, build 48a6621

identical .jhipster/LogEntry.json
INFO! Congratulations, JHipster execution is complete!

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

JDL above

Browsers and Operating System

OSX 10.15.4

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

deftdawg commented Jul 18, 2020

It seems from further inspection that User entity is actually being ignored with a pair warnings:

warn: The table name 'User' is a reserved keyword for at least one of these applications: testmicroservice, so it will be prefixed with the value of 'jhiPrefix'.
warn: An Entity name 'User' was used: 'User' is an entity created by default by JHipster. All relationships toward it will be kept but any attributes and relationships from it will be disregarded.

Workaround

Seems one can force the generation by using a dummy NOTUser class and modifying it post generation and then asking JHipster to regenerate... A bit of a brutal way to work around the problem.

Below I'm generating just the classes, if you have custom code better be careful with the rm -rf src...

jhipster import-jdl ../test.jdl --skip-user-management --ignore-application 
# Run a second time as first dies with: ERROR! Cannot read property 'generator-jhipster' of undefined
jhipster import-jdl ../test.jdl --skip-user-management --ignore-application

# Change all references to NOTUser to User
gsed -i 's/NOTUser/User/' .yo-rc.json
sed -e 's/NOTUser/User/' -e 's/not_user/user/' .jhipster/NOTUser.json > .jhipster/User.json && rm .jhipster/NOTUser.json
grep -in not .jhipster/*.json | cut -d: -f1 | xargs -I {} sed -i '' 's/nOTUser/user/' {}

# Verify all changed, grep below should return nothing
grep -in not .* .jhipster/* 

# Wipe out source folder
rm -rf src/

# Ask JHipster to regenerate each entity
for entity in $(jq -r ".entities | @tsv" .yo-rc.json); do
  jhipster entity $entity --skip-user-management --ignore-application --force
done

# Check that User is created, and we can see it is... 
ls -1rth ./src/main/java/com/mycompany/myapp/domain/*.java
./src/main/java/com/mycompany/myapp/domain/package-info.java
./src/main/java/com/mycompany/myapp/domain/AbstractAuditingEntity.java
./src/main/java/com/mycompany/myapp/domain/PersistentAuditEvent.java
./src/main/java/com/mycompany/myapp/domain/User.java
./src/main/java/com/mycompany/myapp/domain/LogEntry.java

@MathieuAA
Copy link
Member

Hello, thanks for reporting it. I'm fixing it

@colameo
Copy link
Member

colameo commented Jul 19, 2020

Hello, thanks for reporting it. I'm fixing it

...ups, this affects also the JH IDE... I'll create an issue and refer to this.

@deftdawg
Copy link
Author

JH IDE now works as expected, however jhipster import-jdl still bombs out... It looks like skipUserManagement is either not propagating downward through the levels of generator or not being respected somewhere.

Difficult for me to figure out because I haven't found out how to change the logging level....
(DEBUG=jhipster:* LOG_LEVEL=debug node --inspect /usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/cli/cli.js import-jdl ${JDL_FILE} --skip-user-management --ignore-application didn't work)

Thinking maybe I should open an issue in generator-jhipster and close the one here.

@MathieuAA
Copy link
Member

Done in the generator.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants