Как создать отношение сущности к самой себе? Например, иерархические папки

Я пытаюсь создать иерархическую структуру папок. Вот моя папка:

$ yo jhipster:entity Folder
The entity Folder is being created.
Generating field #1
? Do you want to add a field to your entity? Yes
? What is the name of your field? name
? What is the type of your field? String
? Do you want to add validation rules to your field? No
=================Folder=================
name (String)
Generating field #2
? Do you want to add a field to your entity? Yes
? What is the name of your field? parentId
? What is the type of your field? Long
? Do you want to add validation rules to your field? No
=================Folder=================
name (String)
parentId (Long)
Generating field #3
? Do you want to add a field to your entity? No
=================Folder=================
name (String)
parentId (Long)

Я пытаюсь определить, что мне нужно предоставить генератору сущностей jhipster, чтобы он работал. Это то, что у меня есть ...

Generating relationships with other entities
? Do you want to add a relationship to another entity? Yes
? What is the name of the other entity? Folder
? What is the name of the relationship? parent
? What is the type of the relationship? one-to-many
? What is the name of this relationship in the other entity? child

Я на правильном пути? Как мне создать у ребенка отношения «многие к одному»? Я получаю предупреждение, если пытаюсь создать его с помощью объекта «Папка». После этого его невозможно сгенерировать.


person David    schedule 16.12.2015    source источник
comment
Интересный вопрос. Вы нашли решение ?   -  person Pierre Henry    schedule 08.01.2016


Ответы (2)


Вы можете использовать https://jhipster.github.io/jdl-studio/ для записи как jdl для создания сущностей. Посетите https://jhipster.github.io/jhipster-uml/#jdl. для дополнительной информации. Это образец JDL, имеющий отношение к самому себе:

entity RankProperties {
    rank Integer required,
    minExp Integer required,
    maxExp Integer required,
    maxStamina Integer required,
    maxAlly Integer required,
    maxTeam Integer required    
}
enum TaskMode {
    NO_CONTINUE_STAGE_COUNT,
    STAGE_COUNT,
    STAGE_ID
}

entity Task {
    taskMode TaskMode required,
    value Integer   required
}

relationship ManyToOne {
  Task{parent} to Task
}

dto all with mapstruct
service all with serviceClass
person Alireza Hanifi    schedule 23.02.2016
comment
@ Pierre-henry, это мое решение. - person Alireza Hanifi; 23.02.2016

Рекомендую использовать модель jdl.

entity A { property1 String }
relationship OneToMany {
   A{sons} to A{parent}
}

Модель генерирует Java-класс Entity, например (некоторые аннотации игнорируются):

class A {
    @OneToMany(mappedBy="parent")
    private Set<A> sons = new HashSet<>();

    @ManyToOne
    private A parent;
}
person Allens Torres Ruíz    schedule 01.03.2019