Generator-jhipster: import-jdl broken with relationships

Created on 12 Nov 2019  Â·  12Comments  Â·  Source: jhipster/generator-jhipster

Overview of the issue

The import-jdl is currently broken with relationships to User

Here the stacktrace:

➜ jhipster import-jdl bug-tracker.jh
INFO! Using JHipster version installed globally
INFO! Executing import-jdl bug-tracker.jh
INFO! Options: from-cli: true, inline: 
INFO! Found .yo-rc.json on path. This is an existing app
INFO! The JDL is being parsed.
Error: Can't add invalid relationship. Error: In the Many-to-One relationship from Ticket to User, only unidirectionality is supported for a Many-to-One relationship, you should create a bidirectional One-to-Many relationship instead.
Error while parsing applications and entities from the JDL Error: Can't add invalid relationship. Error: In the Many-to-One relationship from Ticket to User, only unidirectionality is supported for a Many-to-One relationship, you should create a bidirectional One-to-Many relationship instead.
Error: Can't add invalid relationship. Error: In the Many-to-One relationship from Ticket to User, only unidirectionality is supported for a Many-to-One relationship, you should create a bidirectional One-to-Many relationship instead.
Reproduce the error

Generate a default JHipster project, and use this JDL:
https://github.com/jhipster/jdl-samples/blob/master/bug-tracker.jh

entity Project {
    name String
}

entity Label {
    label String required minlength(3)
}

entity Ticket {
    title String required,
    description String,
    dueDate LocalDate,
    done Boolean
}

relationship ManyToMany {
    Ticket{label(label)} to Label{ticket}
}

relationship ManyToOne {
    Ticket{project(name)} to Project,
    Ticket{assignedTo(login)} to User{ticket}
}

paginate Ticket with pagination
Related issues

It's probably related to JHipster Core 6.

Suggest a Fix
JHipster Version(s)

6.5.0 and master

$$ bug-bounty $$ $200 area changes JDL

All 12 comments

Ticket{assignedTo(login)} to User{ticket}

This really is confusing. It seems like User will have a field named ticket of type Ticket.

First issue is the one you mentioned @pmverma, can you guess the other one?

The log message is a bit confusing too. But I think it may be a generic one.

Yup the error message sucks, I'm changing it now.
That isn't the worst though. It will inject a ticket field in the User entity, right? But can we? I don't see a skipped user management mentioned anywhere...
The first issue hides this one here.

Thanks @pmverma for your remark on the error message, I'm gonna change it right now.

@pascalgrimaud the sample is just wrong. It shouldn't have worked before.
You should either:

  • remove the injected field in the destination entity
  • do as suggested: have a one-to-many relationship

    • and have the skipUserManagement option (in this case)

Correct me if I'm wrong please.

Original sample (simplified):

entity Ticket

relationship ManyToOne {
  Ticket{assignedTo(login)} to User{ticket}
}

The error message says:

Error: Can't add invalid relationship. Error: In the Many-to-One relationship from Ticket to User, only unidirectionality is supported for a Many-to-One relationship, you should create a bidirectional One-to-Many relationship instead.

Possible solution (MtO, unidirectional):

entity Ticket

relationship ManyToOne {
  Ticket{assignedTo(login)} to User
}

Works because:

  • complies with the MtO creation rule (uni only)
  • complies with having the User entity as part of the relationship and not having an injected field

Other solution (OtM, bidirectional):

entity Ticket

relationship OneToMany {
  User{ticket} to Ticket{assignedTo(login)}
}

Note that it won't work because we inject a field in the User here, so:

  • either the skipUserManagement flag is set in the CLI
  • or the entity is part of an app having the option

@MathieuAA : just try this JDL, using ManyToOne:

entity Project {
    name String
}

entity Label {
    label String required minlength(3)
}

entity Ticket {
    title String required,
    description String,
    dueDate LocalDate,
    done Boolean
}

relationship ManyToMany {
    Ticket{label(label)} to Label{ticket}
}

relationship ManyToOne {
    Ticket{project(name)} to Project,
    Ticket{assignedTo(login)} to User
}

paginate Ticket with pagination

I can generate correctly the entities.
Once, I started the application, I can't add a User to a Ticket, either a Project.
So the create / update are broken here.

You can use my project:

Latest updates after (too?) many tests:

  • generating from the CLI doesn't work neither (the same JSON is generated)
  • no matter what the relationship is (to a User, or whatever), doesn't work
  • made it work by generating an entity with DTO & service

thanks @MathieuAA for the analyze !

I think the title should be renamed to 'Invalid relationships are noticed by the JDL' (yep, I'm trolling).
I've updated the PR, it should be good to go

Closed by jhipster-core v6.0.4.
@MathieuAA : don't forget to claim the bounty here, you deserved it !

Thanks, bounty claim: https://opencollective.com/generator-jhipster/expenses/11777

was too lazy to create two separate claims...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shivroy121 picture shivroy121  Â·  3Comments

frantzynicolas picture frantzynicolas  Â·  3Comments

kaidohallik picture kaidohallik  Â·  3Comments

marcelinobadin picture marcelinobadin  Â·  3Comments

ahmedeldeeb25 picture ahmedeldeeb25  Â·  3Comments