4

I'm using JDL (JHipster 5.8.1) to define my domain model with DTO option:

entity Event {
    title               String maxlength(128)             required,
    bannerUrl           String maxlength(256)             required,
    summary             String maxlength(256)             required
}

entity Tag {
    name                String maxlength(64)             required
}

entity Team {
    title           String maxlength(128) required,
    description     TextBlob
}

relationship ManyToMany {
    Event{tags} to Tag{events}
}

relationship OneToMany {
    Event{teams} to Team{event required}
}

relationship ManyToOne {
    Event{city} to City{events}
}

dto * with mapstruct

I tried to define Events which contains Multiple reusable tags and multiple Teams. The intetions is to make API generate composite JSON which contains all Tags and all Teams inside requiested Event (to avoid N+1 problem in REST)

I expected to get bidirectional relations between Tag <-> Event and Team <-> Event. For ManyToMany relations it is true: I see getter for TagDTO inside EventDTO. But for OneToMany (also ManyToOne) I doesn't see any getter inside EventDTO an have eventId getter inside Team:

public class EventDTO implements Serializable {

    private Long id;

    @NotNull
    @Size(max = 128)
    private String title;

    @NotNull
    @Size(max = 256)
    private String bannerUrl;

    @NotNull
    @Size(max = 256)
    private String summary;

    private Long cityId;

    private Set<TagDTO> tags = new HashSet<>();

The code generated without dto * with mapstruct line produced expected JSON with all child entities if eagerload=true, but this approch could cause security problems.

Is it possible to correct my JDL to produce childEntity-like DTOs but not childId-like DTOs?

nickotinus
  • 323
  • 5
  • 17
  • found any solution ? Facing the same issue – Phani Kiran Gutha Jun 28 '21 at 14:38
  • I also ran into the same problem. It is especially confusing because I found the reference "It will ignore one-to-many relationships and many-to-many relationships on the non-owner side: this matches the way entities work (they have a @JsonIgnore annotation on those fields)." on https://www.jhipster.tech/using-dtos/. But your entity event is owner – Kleinstein11 Jul 06 '21 at 12:59

0 Answers0