Generator-jhipster: JPA Derived Identifier combined with mapstruct generates code that doesn't compile

Created on 6 Nov 2019  路  22Comments  路  Source: jhipster/generator-jhipster

Overview of the issue

Combination of dto with mapstruct and use of jpaDerivedIdentifier doesn't work.

Motivation for or Use Case

Generated code should compile

Reproduce the error

Use the following JDL:

application {
    config {
        baseName mapsIdBugWithDTO
        applicationType microservice
        databaseType sql
        prodDatabaseType postgresql 
    }
    entities *
}

entity A

entity B

relationship OneToOne {
  A to B with jpaDerivedIdentifier
}

dto * with mapstruct

Because of #10739, once the application and entities have been generated with jhipster import-jdl, you have to manually fix .jhipster/A.json and .jhipster/A.json and regenerate both entities with jhipster entity A --regenerate --force and jhipster entity A --regenerate --force

Then you have multiple compilation errors:

[ERROR] src/main/java/com/mycompany/myapp/web/rest/AResource.java:[55,32] cannot find symbol
  symbol:   method getBId()
  location: variable aDTO of type com.mycompany.myapp.service.dto.ADTO
[ERROR] src/main/java/com/mycompany/myapp/service/AService.java:[49,24] cannot find symbol symbol:   method getBId()
  location: variable aDTO of type com.mycompany.myapp.service.dto.ADTO
[ERROR] src/main/java/com/mycompany/myapp/service/dto/ADTO.java:[56,22] cannot find symbol
  symbol:   method getBId()
  location: class com.mycompany.myapp.service.dto.ADTO
[ERROR] src/main/java/com/mycompany/myapp/service/BService.java:[50,24] cannot find symbol
  symbol:   method getAId()
  location: variable bDTO of type com.mycompany.myapp.service.dto.BDTO
[ERROR] src/main/java/com/mycompany/myapp/web/rest/BResource.java:[56,32] cannot find symbol
  symbol:   method getAId()
  location: variable bDTO of type com.mycompany.myapp.service.dto.BDTO
Related issues
Suggest a Fix
JHipster Version(s)

6.4.1

JHipster configuration

See JDL above

Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System

Windows 10

  • [X] Checking this box is mandatory (this is just to show you read everything)
$$ bug-bounty $$ $100 area JDL relationships

Most helpful comment

Possibly related to the comment here: https://github.com/jhipster/generator-jhipster/issues/2899#issuecomment-200603494

All 22 comments

The obvious fix is to release a new version, which I will do very very very soon. Like before the end of the week (hopefully)

But this is blocking :( I'll release ASAP and do the necessary PR

@MathieuAA Are you sure your last comments apply to this issue, and not the other one: #10739 ?

This one. The other one isn't blocking.

@murdos I'm mixing comments, agrred ;) but the fix is the same. I'll do my best to close them before v6.5.0

I've tested the above JDL with JHipster v6.5.0 and I still have the issue.

Ah, that's weird. I'll figure it out.

Actually this is not related to jhipster-core but this is how it will generate when the entity name is a single character.

While you are expecting like a java bean setter/getter naming,

    public Long getBId() {
        return bId;
    }

but in actual, it generates by applying .toLowerCase()

    public Long getbId() {
        return bId;
    }

You can check at https://github.com/jhipster/generator-jhipster/blob/56a5d39cb086ed823af3bf1c7479e766da0f740f/generators/entity-server/templates/src/main/java/package/service/dto/EntityDTO.java.ejs#L211-L214

I don't get the reason behind it but there will be some good one to do lowercases.

I wish github had the :clap: reaction to comment in issues.

Possibly related to the comment here: https://github.com/jhipster/generator-jhipster/issues/2899#issuecomment-200603494

One simple possible thing is to do not allow a single character entity name.
While technically possible to use it but it has no real meaning in real projects.

I don't think it's related to single caracter
I tried this issue in v6.5.0 with similar JDL, replacing entities by a longer name and it failed too

@pascalgrimaud I am saying specifically for the below-mentioned error.

[ERROR] src/main/java/com/mycompany/myapp/web/rest/AResource.java:[55,32] cannot find symbol
  symbol:   method getBId()
  location: variable aDTO of type com.mycompany.myapp.service.dto.ADTO
[ERROR] src/main/java/com/mycompany/myapp/service/AService.java:[49,24] cannot find symbol symbol:   method getBId()
  location: variable aDTO of type com.mycompany.myapp.service.dto.ADTO
[ERROR] src/main/java/com/mycompany/myapp/service/dto/ADTO.java:[56,22] cannot find symbol
  symbol:   method getBId()
  location: class com.mycompany.myapp.service.dto.ADTO
[ERROR] src/main/java/com/mycompany/myapp/service/BService.java:[50,24] cannot find symbol
  symbol:   method getAId()
  location: variable bDTO of type com.mycompany.myapp.service.dto.BDTO
[ERROR] src/main/java/com/mycompany/myapp/web/rest/BResource.java:[56,32] cannot find symbol
  symbol:   method getAId()
  location: variable bDTO of type com.mycompany.myapp.service.dto.BDTO

There we assume getBId() but in actual it is getbId().

@pascalgrimaud did you? I remember seeing it working when we were trying to find the relationship-fetching issue.

I'll try again, maybe my test wasn't good enough

Ah you're right :) I wonder if it's related to the JDL though. I'll try without a JDL file

I think I got it... confirming

Okay, I'm fixing it and releasing it in a few minutes. The issue is the useJpa in both entities (in the JSON files)

This should be good now by the way (completely forgot about this issue, sorry)

@MathieuAA @murdos : what is the state of this issue ? Is it fixed or not yet ?

Fixed on my end.

ok then, let's close this.
@murdos: don't hesitate to reopen if it's not the case

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ahmedeldeeb25 picture ahmedeldeeb25  路  3Comments

tomj0101 picture tomj0101  路  3Comments

DanielFran picture DanielFran  路  3Comments

RizziCR picture RizziCR  路  3Comments

trajakovic picture trajakovic  路  4Comments