Search code examples
jpajhipsterself-reference

jhipster - JPA entity with self reference


I am trying out jhipster and I wonder how to define a self reference within an entity. Something like: a "topic" has a field refering itself as parent or child. Going through the generator I did not see a possibility to do so.

That`s why I generated a topic entity and added a field myself in the entity, howevever, it seems like changes in the entity are not picked up by liquibase.

Readint the docs it seems like the topic.json file from jhipster is parsed for this, but, that does not support the self reference. So I am kind of stuck here.

Any ideas how to achieve what I want?

Thanks, Sven


Solution

  • liquibase creates the database tables using changelogs. Look into the resources/config/liquibase/changelog folder there should be a file named like "201531081212_added_entity_Topic.xml"

    when you're adding properties, you have to change the table description of this changelog.

    normally, it would be better to create a new, additional changelog when adding/removing columns or tables. This should contain somthing like this:

    <addColumn tableName="TOPIC">
        <column name="topic_id" type="bigint"/>
    </addColumn>
    

    or parent_id or how you named the field in the entity class.

    asfair there are also some maven goals as part of the maven liquibase plugin to generate a new changelog.

    Changing/Migrating entities is not yet supportet well by jhipster...