generator-jhipster: import-jdl does not respect skipUserManagement cli params or jdl settings

Overview of the issue

The command stacktrace states that skipUserManagement can be used to enable relationships between a custom defined User entity and Company entity, however JHipster jdl/import-jdl does not accept any form of the setting: neither the command line argument --skip-user-management, nor the alternative specifying // skip-user-management as first line of JDL file work.

According JHipster documentation --skip-user-management should be able to disable automatic generation of User and Authority entities so that those entities can be used in normal entity relationships.

INFO! Using JHipster version installed globally
INFO! Executing import-jdl test.jdl
INFO! The JDL is being parsed.
warn: In the One-to-Many relationship from Company to User, 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 'Company'. 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 'Company'. You can have this by using the 'skipUserManagement' option.
Error: Relationships from the User entity is not supported in the declaration between 'User' and 'Company'. You can have this by using the 'skipUserManagement' option.
    at checkForForbiddenUseOfUserAsSource (/usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/validators/relationship_validator.js:89:11)
    at checkForInvalidUseOfTheUserEntity (/usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/validators/relationship_validator.js:83:3)
    at RelationshipValidator.validate (/usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/validators/relationship_validator.js:37:5)
    at /usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/validators/business_error_checker.js:158:17
    at /usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/core/jdl_object.js:202:7
    at /usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/core/jdl_relationships.js:90:7
    at Array.forEach (<anonymous>)
    at JDLRelationships.forEach (/usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/core/jdl_relationships.js:89:20)
    at JDLObject.forEachRelationship (/usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/core/jdl_object.js:201:24)
    at BusinessErrorChecker.checkForRelationshipErrors (/usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/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 'Company'. You can have this by using the 'skipUserManagement' option.
Error: Relationships from the User entity is not supported in the declaration between 'User' and 'Company'. You can have this by using the 'skipUserManagement' option.
    at checkForForbiddenUseOfUserAsSource (/usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/validators/relationship_validator.js:89:11)
    at checkForInvalidUseOfTheUserEntity (/usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/validators/relationship_validator.js:83:3)
    at RelationshipValidator.validate (/usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/validators/relationship_validator.js:37:5)
    at /usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/validators/business_error_checker.js:158:17
    at /usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/core/jdl_object.js:202:7
    at /usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/core/jdl_relationships.js:90:7
    at Array.forEach (<anonymous>)
    at JDLRelationships.forEach (/usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/core/jdl_relationships.js:89:20)
    at JDLObject.forEachRelationship (/usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/node_modules/jhipster-core/lib/core/jdl_object.js:201:24)
    at BusinessErrorChecker.checkForRelationshipErrors (/usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/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 'Company'. You can have this by using the 'skipUserManagement' option.
    at module.exports (/usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/cli/import-jdl.js:428:31)
    at /usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/cli/jdl.js:93:51
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

I attempted to turn on debug logging level

DEBUG=generator-jhipster:* LOG_LEVEL=debug node --inspect /usr/local/Cellar/jhipster/6.10.1/libexec/lib/node_modules/generator-jhipster/cli/cli.js import-jdl test.jdl --skip-user-management --ignore-application

The command runs, but it does not change logging level… if someone could tell me the correct syntax, I would be happy to investigate it further to see if I can determine where the breakdown occurs.

Motivation for or Use Case

For the project I’m working on, I use OIDC/OAuth2 to handle user authentication and identity management, we still need a User representation within our database for data-ownership.

We need to be able to update entities and regenerate classes as the project evolves, currently this bug blocks us from being able to do that.

Reproduce the error

jhipster jdl test.jdl --skip-user-management test.jdl is attached in JHipster configuration section

Related issues

Issue was first opened against JHipster core jhipster/jhipster-core#476, but it seems more suitable to be here as it may not be a problem with JHipster only rather how the classes are generated.

Suggest a Fix

Skip User Management doesn’t work through import jdl at all… Configuration is not being respected by lower level classes in generator-jhipster.

JHipster Version(s)

6.10.1

JHipster configuration
// skip-user-management

// application {
//     config {
//         packageName com.test.project.entities
//     }
//     entities *
// }

DEFAULT_MIN_LENGTH = 2
DEFAULT_MAX_LENGTH = 50

entity Company {
    name String required unique minlength(DEFAULT_MIN_LENGTH)
    abbreviation String required unique 
    config String required
    entities String required
    logo String
}

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

relationship OneToMany {
    Company to User{company(name)}
}

relationship ManyToOne {
    User to Company {user(name)}
}
Entity configuration(s) entityName.json files generated in the .jhipster directory

N/A

Browsers and Operating System

OSX 10.15

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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (18 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for looking into this @MathieuAA Thanks for the suggestion @mshima. I gave it a shot and here’s what I found:

  • removing the ManyToOne back link did allow the JDL to parse and JHipster ran generating an application
  • No Company entity was generated (no .jhipster directory)

Have you added entities *?

I am reopening since in my opinion there are some bugs here.

  • It’s possible to create entity called User and relationships like the example using prompts, tried and generated, didn’t tried to execute.
  • I’ve managed to bypass the error with some changes.
  • Company entity is generating, with user relationship correctly:
"relationships": [
    {
      "relationshipType": "one-to-many",
      "otherEntityName": "user",
      "otherEntityRelationshipName": "company",
      "relationshipName": "user"
    },
    {
      "relationshipType": "one-to-many",
      "otherEntityName": "user",
      "otherEntityRelationshipName": "company",
      "relationshipName": "user"
    }
  ],

At current state custom User entity is completely broken using jdl. At least we should throw an error if entity User is found in the jdl.

It’s related to https://github.com/jhipster/jhipster-core/pull/278 and https://github.com/jhipster/generator-jhipster/issues/10425

Done.

I have identified 3 cases that I think they are bugs:

  • User entity is ignored by jdl when skipUserManagement:
application {
    config {
        skipUserManagement true
    }
    entities *
}

entity User {
    name String required
}

and

application {
    config {
        skipUserManagement true
    }
    entities *
}

entity Company {
    name String required unique
}

entity User {
    name String required
}

relationship OneToMany {
    Company to User{company(name)}
}

This second example Company is generated with user relationship but User is missing.

  • jdl should throw when trying to override built-in User entity.
application {
    entities User
}

entity User {
    name String required
}
  • jdl should allow ManyToOne from user to another entity if skipUserManagement.
application {
    config {
        skipUserManagement true
    }
    entities *
}

entity Company {
    name String required unique
}

entity User {
    name String required
}

relationship ManyToOne {
    User to Company {user(name)}
}