jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.54k stars 4.02k forks source link

Cannot generate entity relationships with CLI #16330

Closed DasHasan closed 1 year ago

DasHasan commented 3 years ago

I have two entities named Teacher and Student and I want to generate a relationship between those two with the cli. Both entities have already been created and are listed in the .jhipster directory.

edit: generating relationships with a jdl file works as intended

Overview of the issue

If I try to generate relationships with the CLI I get the following error, even though both entities exists:

ERROR! Error at entity Teacher: could not find the other side of the relationship {
    "relationshipName": "student",
    "otherEntityName": "student",
    "relationshipType": "one-to-many",
    "otherEntityRelationshipName": "teacher",
    "otherEntity": "[Student Entity]",
    "otherEntityField": "id",
    "ownerSide": false,
    "collection": true,
    "otherSideReferenceExists": false,
    "otherEntityIsEmbedded": false
}

image

Motivation for or Use Case

It would be great if I could generate relationships from the cli so I don't have to write a jdl definition for all my entities

Reproduce the error

Create two entities and try to generate a relationship afterwards.

entity Teacher {
  name String
}
entity Student {
  name String
}
//relationship OneToMany {
//  Teacher to Student
//}
Related issues
Suggest a Fix
JHipster Version(s)

7.2.0

JHipster configuration
<details>
<summary>.yo-rc.json file</summary>
<pre>
{
  "generator-jhipster": {
    "applicationType": "monolith",
    "baseName": "demo1",
    "jhipsterVersion": "7.2.0",
    "skipClient": false,
    "skipServer": false,
    "skipUserManagement": false,
    "skipCheckLengthOfIdentifier": false,
    "skipFakeData": false,
    "jhiPrefix": "jhi",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "testFrameworks": [],
    "blueprints": [],
    "otherModules": [],
    "pages": [],
    "creationTimestamp": 1631869615176,
    "serviceDiscoveryType": "no",
    "reactive": false,
    "authenticationType": "jwt",
    "packageName": "com.mycompany.myapp",
    "serverPort": "8080",
    "cacheProvider": "ehcache",
    "enableHibernateCache": true,
    "databaseType": "sql",
    "devDatabaseType": "h2Memory",
    "prodDatabaseType": "mysql",
    "buildTool": "maven",
    "serverSideOptions": [],
    "websocket": false,
    "searchEngine": false,
    "messageBroker": false,
    "enableSwaggerCodegen": false,
    "clientFramework": "angularX",
    "withAdminUi": true,
    "clientTheme": "none",
    "enableTranslation": false,
    "nativeLanguage": "en",
    "jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "devServerPort": 4200,
    "clientPackageManager": "npm",
    "clientThemeVariant": "",
    "enableGradleEnterprise": false,
    "languages": ["en", "fr"],
    "lastLiquibaseTimestamp": 1631870020000,
    "entities": ["Teacher", "Student"]
  }
}

</pre>
</details>

##### **JDL for the Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory**

<details>
<summary>JDL entity definitions</summary>

<pre>
entity Teacher {
  name String
}
entity Student {
  name String
}
relationship OneToMany {
  Teacher{student} to Student{teacher}
}

</pre>
</details>

##### **Environment and Tools**

openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7)
OpenJDK 64-Bit Server VM Temurin-11.0.12+7 (build 11.0.12+7, mixed mode)

git version 2.25.1

node: v14.17.6

npm: 6.14.15
Entity configuration(s) entityName.json files generated in the .jhipster directory
$ find .jhipster -name '*json' -print -exec cat {} \;
.jhipster/Teacher.json
{
  "fields": [
    {
      "fieldName": "name",
      "fieldType": "String"
    }
  ],
  "relationships": [
    {
      "relationshipType": "one-to-many",
      "otherEntityName": "student",
      "otherEntityRelationshipName": "teacher",
      "relationshipName": "student"
    }
  ],
  "service": "no",
  "readOnly": false,
  "pagination": "no",
  "name": "Teacher",
  "changelogDate": "20210917091229",
  "entityTableName": "teacher",
  "dto": "no",
  "jpaMetamodelFiltering": false,
  "fluentMethods": true,
  "embedded": false,
  "applications": "*"
}
.jhipster/Student.json
{
  "fields": [
    {
      "fieldName": "name",
      "fieldType": "String"
    }
  ],
  "relationships": [
    {
      "relationshipType": "many-to-one",
      "otherEntityName": "teacher",
      "otherEntityRelationshipName": "student",
      "relationshipName": "teacher"
    }
  ],
  "service": "no",
  "readOnly": false,
  "pagination": "no",
  "name": "Student",
  "changelogDate": "20210917091340",
  "entityTableName": "student",
  "dto": "no",
  "jpaMetamodelFiltering": false,
  "fluentMethods": true,
  "embedded": false,
  "applications": "*"
}
Browsers and Operating System

edit: I just found this: https://github.com/jhipster/generator-jhipster/blob/b11abef0a11e1ef25fac28a032bd21f26d79a166/utils/relationship.js#L117-L125

Why is it, that the OneToMany relation gets filtered explicitly?

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted. We are accepting PRs :smiley:. Comment or this will be closed in 7 days

DasHasan commented 3 years ago

Any updates on this or am I missing something?

mshima commented 2 years ago

Currently adding a one-to-many relationship without the many-to-one in the other side will cause this problem. Reworking entities prompt is in my todo, but not sure when I will manage to do it.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted. We are accepting PRs :smiley:. Comment or this will be closed in 7 days

gothic-explorer commented 1 year ago

Is there any feedback on this ?

Ayuob commented 1 year ago

any news about this ?

mshima commented 1 year ago

Will be fixed for v8.

mshima commented 1 year ago

I suppose this is fixed in main by https://github.com/jhipster/generator-jhipster/pull/21509 and https://github.com/jhipster/generator-jhipster/pull/21535