jhipster / jhipster-core

JHipster Domain Language, used by JHipster UML and JDL-Studio to generate entities
Apache License 2.0
345 stars 116 forks source link

Import a jdl definition which uses User entity #52

Closed lrkwz closed 8 years ago

lrkwz commented 8 years ago
Overview of the issue

(from https://github.com/jhipster/generator-jhipster/issues/3977)

I wish to use the User entity in order to associate each User with a Customer.

JDL-Importing such a definition generates an error

$ yo jhipster:import-jdl jhipster-jdl.jh
The jdl is being parsed.
Error jhipster:import-jdl jhipster-jdl.jh 

ERROR! Error while parsing entities from JDL
[object Object]

further inspecting the error is In the relationship between User and Customer, User is not declared.

Reproduce the error
  1. yo jhipster to produce a basic project
  2. Create jhipster-jdl.jh
    relationship OneToMany{
        User{customer} to Customer
     } 
    entity Customer {

        legalName String required
        birthDate LocalDate
        vatid String
        business Boolean required
    }
  1. Import $ yo jhipster:import-jdl jhipster-jdl.jh
    JHipster Version(s)

BTW I'm quite sure it is a regression bug.

test-customer@0.0.0 /home/lrkwz/generator-jhipster-extend-user
└── generator-jhipster@3.5.1 
JHipster configuration, a .yo-rc.json file generated in the root folder
{
  "generator-jhipster": {
    "jhipsterVersion": "3.5.1",
    "baseName": "test_customer",
    "packageName": "com.mycompany.myapp",
    "packageFolder": "com/mycompany/myapp",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "hibernateCache": "ehcache",
    "clusteredHttpSession": "no",
    "websocket": "no",
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "prodDatabaseType": "mysql",
    "searchEngine": "no",
    "buildTool": "maven",
    "enableSocialSignIn": false,
    "jwtSecretKey": "308c83521a7f64cc27d75631dc2d1844913fe224",
    "useSass": false,
    "applicationType": "monolith",
    "testFrameworks": [
      "gatling"
    ],
    "jhiPrefix": "jhi",
    "enableTranslation": true,
    "nativeLanguage": "en",
    "languages": [
      "en",
      "it"
    ]
  }
}
Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System

java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

git version 1.9.1

node: v4.2.1

npm: 3.10.5

bower: 1.7.9

gulp: [14:40:57] CLI version 1.2.2 [14:40:57] Local version 3.9.1

yeoman: 1.7.1

Docker version 1.11.2, build b9f10c9

docker-compose version 1.7.1, build 0a9ab35

lrkwz commented 8 years ago

BTW Using

$ jhipster-uml jhipster-jdl.jh 

somehow leads to a result.

MathieuAA commented 8 years ago

Hi, I don't have time right now to check this out, but it seems a very simple issue... I'll fix it tonight. In the meantime, @deepu105 can you look into this?

Update: the issue is here, if there's one in the first place.

deepu105 commented 8 years ago

Relationship from User entity is not supported by JHipster and JDL and its clearly documented as well

You can only do relationships to User entity that too only many-to-one, one-to-one and many-to-many and User cannot be owner in any of these case

relationship OneToMany{
        User{customer} to Customer
     } 
deepu105 commented 8 years ago

Not sure why the error message appears as object though

MathieuAA commented 8 years ago

Thanks Deepu :)

deepu105 commented 8 years ago

Its weird when I run the same JDL I see proper error message but @irkwz seems to get [object Object]

PS D:\Projects\test\testNew> yo jhipster:import-jdl .\jhipster-jdl.jh
The jdl is being parsed.
Error jhipster:import-jdl .\jhipster-jdl.jh

ERROR! Error while parsing entities from JDL
Relationships from User entity is not supported in the declaration between User and Customer.
PS D:\Projects\test\testNew>

@MathieuAA can you run the JDL when you have time and see if you are getting the same error as mine above.

lrkwz commented 8 years ago

Just discovered that the installed core is "jhipster-core@1.1.2" which is the declared dependency for generator 3.5.1

Can I safely upgrade the core? how?

lrkwz commented 8 years ago

@deepu105 what you say is perfectly reasonable to me but still the is the problem:

I've created a simple project which you can use https://github.com/lrkwz/jhipster-extend-user-test

Try

yo jhipster:import-jdl customer.jh user-to-customer.jh

and

yo jhipster:import-jdl customer.jh customer-to-user.jh

where user-to-customer.jh is

relationship OneToMany{
    User{customer} to Customer
}

and customer-to-user.js is

relationship ManyToOne{
    Customer{user} to User
}
deepu105 commented 8 years ago

@lrkwz as I said we do not support relationships from User so your customer-to-user.js is valid but user-to-customer.jh is invalid as User is a special entity and we do not support any relationships that alter this entity. If you need a relationship from User you would have to do it manually by hand.

deepu105 commented 8 years ago

The project you shared doesnt have any relationship to customer from User, may be you used an older version of JDL or JHUML where the error message was not thrown and the relationship was just ignored