1

I am trying to associate a post to the currently logged in user but I get errors when I try to generate entities. What I'm trying to do seems similar to examples I see online and the documentation.

https://www.jhipster.tech/user-entity/

I'm using JHipster 8 installed from npm npm install -g generator-jhipster

I tried to generate entities with the following jdl file:

entity Post {
    content String,
}

/**
 * One to many relationship.
 */
relationship OneToMany {
    Post{user} to User
}

and got the following error:

ERROR! In the relationship between Post and User, User is not declared. If 'User' is a built-in entity declare like 'Post to User with builtInEntity'.

Following the advice from the error message I tried adding "with builtInEntity"

relationship OneToMany {
    Post{user} to User with builtInEntity
}

Then I got the following error

ERROR! Error at entity Post: could not find the other side of the relationship {
    "relationshipSide": "left",
    "relationshipType": "one-to-many",
    "otherEntityName": "user",
    "relationshipName": "user",
    "relationshipWithBuiltInEntity": true,
    "otherEntity": "[User Entity]",
    "ownerSide": false,
    "otherEntityField": "id",
    "relationshipLeftSide": true,
    "relationshipRightSide": false,
    "collection": true,
    "otherSideReferenceExists": false,
    "otherEntityIsEmbedded": false
}
Daniel
  • 11
  • 2
  • If you're generating a monolith then I think it's a bug and you should open an issue on github. If you're generating a microservice, then it's normal.It could help also to try to reproduce with JHipster 7.9.3 – Gaël Marziou Jul 12 '23 at 10:09
  • I tried to install an older version and I tried to uninstall it first as well: `npm install -g generator-jhipster@7.9.3` I'm not doing it wrong am I? The jhipster command wouldn't work when I downgraded: `Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/util/namespace' is not defined by "exports" in C:\Users\daniel.popov\AppData\Roaming\npm\node_modules\generator-jhipster\node_modules\yeoman-environment\package.json` – Daniel Jul 12 '23 at 12:12
  • Try installing the maintenance version of 7.9.3 to address this npm issue: `npm install -g jhipster/generator-jhipster#v7.x_maintenance` – jelharou Jul 12 '23 at 13:55
  • JHipster 7 does not support same versions of nodejs, it could be the reason for this error you see. – Gaël Marziou Jul 12 '23 at 16:58

1 Answers1

2

The problem here is that you are specifying the binding. I had the same issue, and fixed it by removing the binding:

relationship OneToOne {
    Member to User with builtInEntity
}

So, in your case, should be:

relationship OneToMany {
    Post to User with builtInEntity
}

With this, it will create a user_id on the entity