Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler errors due to wrong mapper generation #372

Open
1 task done
egvimo opened this issue Mar 14, 2023 · 0 comments
Open
1 task done

Compiler errors due to wrong mapper generation #372

egvimo opened this issue Mar 14, 2023 · 0 comments

Comments

@egvimo
Copy link
Contributor

egvimo commented Mar 14, 2023

Overview of the issue

Generating the app with Mapstruct leads to wrong mappings for some entitites. Which in turn leads to compiler errors.

Reproduce the error

JDL
application {
    config {
    baseName sample
    packageName sample
    applicationType microservice
    authenticationType oauth2
    serverPort 8081
    buildTool gradle
    cacheProvider no
    clientFramework no
    databaseType sql
    prodDatabaseType postgresql
    devDatabaseType postgresql
    serviceDiscoveryType no
    enableTranslation false
    messageBroker kafka
    skipClient true
    skipUserManagement true
  }
  entities *
  dto * with mapstruct
}

entity ParentEntity {
  parentRequiredField String required
}

entity ChildEntity {
  childField String
}

relationship ManyToOne {
  ChildEntity{user(login) required} to User
}

relationship OneToMany {
  ParentEntity{child} to ChildEntity{parent(parentRequiredField) required}
}

Generating with the above JDL produces the following Mapper:

ChildEntityMapper
@Mapper(componentModel = "spring")
interface ChildEntityMapper :
    EntityMapper<ChildEntityDTO, ChildEntity> {

    @Mappings(
        Mapping(target = "user", source = "user", qualifiedByName = ["userLogin"]), Mapping(target = "parent", source = "parent", qualifiedByName = ["parentEntityParentRequiredField"])
    )
    override fun toDto(s: ChildEntity): ChildEntityDTO

    @Named("userLogin")
    @BeanMapping(ignoreByDefault = true)

    @Mappings(
        Mapping(target = "id", source = "id"), Mapping(target = "login", source = "login")
    )
    fun toDtoUserLogin(user: User): UserDTO

    @Named("parentEntityParentRequiredField")
    @BeanMapping(ignoreByDefault = true)

    @Mappings(
        Mapping(target = "id", source = "id"), Mapping(target = "login", source = "login"), Mapping(target = "parentRequiredField", source = "parentRequiredField")
    )
    fun toDtoParentEntityParentRequiredField(parentEntity: ParentEntity): ParentEntityDTO
}

The last function toDtoParentEntityParentRequiredField has a mapping annotation for the login field. But the parent entity does not have this field.

KHipster Version(s)

v1.16.0

  • Checking this box is mandatory (this is just to show you read everything)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant