Search code examples
hibernatejhipsterehcachejhipster-registry

Jhipster EHCache doesn't evict id from duplicated entity


I'm actually developing a jhipster application. It's an awsome code generator but it didn't allow me to make relationships to default User entity. So i foundout the table name of that entity and I made another entity MyUser linked to the same table on bbdd. It seems to work fine and generated me the jpa relationships correctly, but instead ine class i had 2 different classes. But after a time I have realised if i change one of that entities, the other one doesn't change.If I quit the cache from one of that entities it seems to work. How can I prevent this from happening without disabling that entity's cache?


Solution

  • Yes. Hibernate doesn't like two entities on the same table. Please don't do that.

    Actually, referencing the existing User class works perfectly. I do it all the time.

    Just generate your new entity and add a relationship. Then specify "user" as the other entity name and that's it. If you look at the final .json file created in the .jhipster directory, it should look like this (the otherEntityField is the field you want to see on the generated CRUD GUI):

    "relationships": [
        {
            "relationshipName": "user",
            "otherEntityName": "user",
            "relationshipType": "many-to-one",
            "otherEntityField": "login"
        }
    ]