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.44k stars 4.02k forks source link

many-to-many relations not generated correctly #4537

Closed jkransen closed 7 years ago

jkransen commented 7 years ago
Overview of the issue

When I create a new entity, and try to add a many-to-many relation to an existing entity, there are a few imperfections in the generated code.

The existing entity does not get an added collection for the new entity.

The mappedBy also references a non-existent remote relation.

I tried setting the new entity to be the owner and not to be so, with the same effect.

There is no liquibase code for generating an intermediate table. There are no foreign keys added.

Motivation for or Use Case
Reproduce the error
Related issues
Suggest a Fix
JHipster Version(s)

v3.11.0

JHipster configuration, a .yo-rc.json file generated in the root folder

{ "generator-jhipster": { "jhipsterVersion": "3.11.0", "baseName": "scvalidator", "packageName": "nl.logius.scvalidator", "packageFolder": "nl/logius/scvalidator", "serverPort": "8080", "authenticationType": "jwt", "hibernateCache": "ehcache", "clusteredHttpSession": false, "websocket": false, "databaseType": "sql", "devDatabaseType": "postgresql", "prodDatabaseType": "postgresql", "searchEngine": false, "messageBroker": false, "buildTool": "maven", "enableSocialSignIn": false, "jwtSecretKey": "21235574ecf789dd03e2128e1868087bc7eb27b4", "useSass": false, "applicationType": "monolith", "testFrameworks": [ "gatling", "cucumber", "protractor" ], "jhiPrefix": "jhi", "enableTranslation": false } }

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

existing entity:

{ "fluentMethods": true, "relationships": [], "fields": [ { "fieldName": "naam", "fieldType": "String", "fieldValidateRules": [ "required" ] } ], "changelogDate": "20161123162003", "dto": "no", "service": "serviceImpl", "entityTableName": "samenwerkingsverband", "pagination": "pagination" }

new entity:

{ "fluentMethods": true, "relationships": [ { "relationshipName": "type", "otherEntityName": "organisatietype", "relationshipType": "many-to-one", "otherEntityField": "naam" }, { "relationshipName": "systeemleverancier", "otherEntityName": "systeemleverancier", "relationshipType": "many-to-one", "otherEntityField": "naam" }, { "relationshipName": "samenwerkingsverband", "otherEntityName": "samenwerkingsverband", "relationshipType": "many-to-many", "ownerSide": false, "otherEntityRelationshipName": "organisatie" } ], "fields": [ { "fieldName": "naam", "fieldType": "String", "fieldValidateRules": [ "required" ] }, { "fieldName": "opmerkingen", "fieldType": "String" } ], "changelogDate": "20161123162836", "dto": "no", "service": "serviceImpl", "entityTableName": "organisatie", "pagination": "pagination" }

Browsers and Operating System
jdubois commented 7 years ago

From what I see here (I didn't re-generate your project, there are missing entities in your conf):

So quite logically this is failing, there is no owner to that relationship.

You can have a look at https://jhipster.github.io/managing-relationships/#5 for more informations on many-to-many relationships.

jkransen commented 7 years ago

In a previous attempt the new entity was the owner, with the same effect. I will try again, and take a look at your link.

jdubois commented 7 years ago

@jkransen yes, but you had a non-owner side? I think we only support bidirectional many-to-many mappings

jkransen commented 7 years ago

Thanks, your link was very helpful. I did not mention the relation in the firstly created entity because I thought it would fail. Now it works perfectly!

jdubois commented 7 years ago

Great :-)