Generator-jhipster: Detect content type built-in field conflicts.

Created on 31 Oct 2020  路  11Comments  路  Source: jhipster/generator-jhipster

Overview of the issue

I don't know why it happens, but I've used the same entity in different flavours (monlithic, microservices application), every time I encounter this problem where a field is created twice in the JPA class, DTOs, webapp... everywhere!

Excuse me but I had to edit the .yo-rc.json and the JDL in order to remove some sensible information, and to simplify it. It appartains to a very large project. Relationships where removed and package name edited by keeping the same structure. Let me know if you need further info.

I noticed this in the test class:

    private static final String DEFAULT_QR_CODE_CONTENT_TYPE = "image/jpg";
    private static final String UPDATED_QR_CODE_CONTENT_TYPE = "image/png";

    private static final String DEFAULT_QR_CODE_CONTENT_TYPE = "AAAAAAAAAA";
    private static final String UPDATED_QR_CODE_CONTENT_TYPE = "BBBBBBBBBB";
It makes me think that the content-type field is added by jhipster automatically (it doesn't contain a random string, but a `image/jpg` instead). Maybe when I executed `export-jdl`, the field was exported, and that messed up everything when re-importing the JDL. ##### **Motivation for or Use Case** The duplicated field must be deleted manually from all over the server & client application. An extract of the JPA entity class:
    /**
     * QR Tag applied on the vehicle
     */
    @Lob
    @Column(name = "qr_code")
    private byte[] qrCode;

    @Column(name = "qr_code_content_type")
    private String qrCodeContentType;

    /**
     * QR imageBlob byte content
     */
    @Column(name = "qr_code_content_type")
    private String qrCodeContentType;

    /**
     * Current vehicle status
     */
    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false)
    private VehicleStatus status;
##### **Reproduce the error** 1. Create a JDL file 2. Create an entity 3. Add field: `qrCode ImageBlob` 4. Add another field: `qrCodeContentType String` 5. Run `import-jdl` by passing the JDL 6. `qrCodeContentType` field will be duplicated everywhere ##### **Related issues** Not properly related, but in issue #12837 I mentioned that comments are not always in place. Maybe that can start from this issue. ##### **Suggest a Fix** For what I can see, it looks like a parsing problem. I don't know if it depends on two fields having a similar name, or the ImageBlob type... or maybe both?! ##### **JHipster Version(s)** `6.10.4` ##### **JHipster configuration**
.yo-rc.json file
{
  "generator-jhipster": {
    "authenticationType": "oauth2",
    "cacheProvider": "hazelcast",
    "serverPort": "8082",
    "serviceDiscoveryType": "eureka",
    "skipUserManagement": true,
    "baseName": "delivery",
    "buildTool": "maven",
    "databaseType": "sql",
    "devDatabaseType": "postgresql",
    "enableHibernateCache": true,
    "enableSwaggerCodegen": true,
    "enableTranslation": true,
    "jhiPrefix": "pot",
    "languages": ["it", "en", "fr", "de", "pt-pt", "es"],
    "messageBroker": "kafka",
    "nativeLanguage": "it",
    "prodDatabaseType": "postgresql",
    "searchEngine": false,
    "skipClient": true,
    "testFrameworks": ["gatling"],
    "websocket": false,
    "applicationType": "microservice",
    "dtoSuffix": "DTO",
    "packageName": "it.my.project",
    "packageFolder": "it/my/project",
    "jhipsterVersion": "6.10.4",
    "creationTimestamp": 1604087280182,
    "clientPackageManager": "npm",
    "embeddableLaunchScript": false,
    "entitySuffix": "",
    "otherModules": [],
    "blueprints": []
  },
  "entities": [
    "Vehicle"
  ]
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory


JDL entity definitions



entity Vehicle {
  /**
   * Since when the vehicle will be available
   */
  activationDate LocalDate required,
  /**
   * Vehicle code encoded in it's QR Tag
   */
  hashCode UUID required,
  /**
   * QR Tag applied on the vehicle
   */
  qrCode ImageBlob,
  /**
   * QR imageBlob byte content
   */
  qrCodeContentType String,
  /**
   * Current vehicle status
   */
  status VehicleStatus required,
  lastUpdate Instant
}

enum VehicleType {
  CAR,
  TRUCK
}

enum VehicleStatus {
  AVAILABLE,
  UNAVAILABLE,
  MOVING,
  STOPPED,
  UNDER_REPAIR
}

dto Vehicle with mapstruct
micrservice Vehicle with delivery
paginate Vehicle with pagination

Entity configuration(s) entityName.json files generated in the .jhipster directory
{
  "name": "Vehicle",
  "fields": [
    {
      "fieldName": "activationDate",
      "fieldType": "LocalDate",
      "javadoc": "Since when the vehicle will be available",
      "fieldValidateRules": ["required"]
    },
    {
      "fieldName": "hashCode",
      "fieldType": "UUID",
      "javadoc": "Vehicle code encoded in it's QR Tag",
      "fieldValidateRules": ["required"]
    },
    {
      "fieldName": "qrCode",
      "fieldType": "byte[]",
      "javadoc": "QR Tag applied on the vehicle",
      "fieldTypeBlobContent": "image"
    },
    {
      "fieldName": "qrCodeContentType",
      "fieldType": "String",
      "javadoc": "QR imageBlob byte content"
    },
    {
      "fieldName": "status",
      "fieldType": "VehicleStatus",
      "javadoc": "Current vehicle status",
      "fieldValues": "AVAILABLE,UNAVAILABLE,MOVING,STOPPED,UNDER_REPAIR",
      "fieldValidateRules": ["required"]
    },
    {
      "fieldName": "lastUpdate",
      "fieldType": "Instant"
    }
  ],
  "relationships": [ ],
  "changelogDate": "19700119135804",
  "javadoc": "",
  "entityTableName": "vehicle",
  "dto": "mapstruct",
  "pagination": "pagination",
  "service": "serviceClass",
  "jpaMetamodelFiltering": false,
  "fluentMethods": true,
  "readOnly": false,
  "embedded": false,
  "clientRootFolder": "",
  "applications": ["gateway", "delivery"],
  "microserviceName": "delivery"
}

Browsers and Operating System

Linux 5.3.0-53-generic #47~18.04.1-Ubuntu SMP Thu May 7 13:10:50 UTC 2020 x86_64 x86_64 GNU/Linux

  • [x] Checking this box is mandatory (this is just to show you read everything)
area stale jhipster-internals

Most helpful comment

The *ContentType problem is related to the generator, it should error when this conflict happens.

I didn't try to reproduce swagger problem, but it is unrelated to this issue, if there is a problem we should handle it in another issue.

All 11 comments

it's how JHipster works. It will add the field qrCodeContentType String for you. You didn't need to define it.
If you want to define a specific content type, try to use another name, so it won't conflict with the existing one, which will be generated

That's totally, ok. But consider that one can also export a jdl, and then re-import it again (that's what I did).
Shouldn't be the generated field removed from the exported jdl, to avoid the duplicate ?

oh indeed, it shouldn't be exported

Take this with tweezers but... I suspect that when an ImageBlob field is present, and enableSwaggerCodegen true then in the DTO of the class where the ImageBlob field is present, swagger annotations are being created for relationships, while that shouldn't happen as no reference to releationship is generated in the DTO (it causes a compile error).

@pascalgrimaud have you managed to reproduce?
I couldn't:

$ jhipster jdl --inline 'application{entities *} entity Blob {qrCode ImageBlob}' --skip-install
$ jhipster export-jdl
.
.
.
entity Blob {
  qrCode ImageBlob
}

Same with:

npx [email protected] jdl --inline 'application{entities *} entity Blob {qrCode ImageBlob}' --skip-install

@mshima I had to remove some confidential data from jdl & yo-rc, sorry for that.
Regarding the problem of swagger annotations, it happens in all DTO classes, not only where the generated field is (relates to #12837)

@funder7 you should remove *ContentType fields from every entity.

@mshima : not with my computer, I didn't try to reproduce. I'm changing the label and will try to reproduce later

The JDL sample parsing was failing with an error for me... (micrservice => microservice), and the comments are badly written. Which is interesting. Gotta investigate.

And I can reproduce the issue by removing the comments. I agree with @mshima about the solution, it should also be documented.

The *ContentType problem is related to the generator, it should error when this conflict happens.

I didn't try to reproduce swagger problem, but it is unrelated to this issue, if there is a problem we should handle it in another issue.

This issue is stale because it has been open 30 days with no activity.
Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted.
We are accepting PRs :smiley:.
Comment or this will be closed in 7 days

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomj0101 picture tomj0101  路  3Comments

edvjacek picture edvjacek  路  3Comments

SudharakaP picture SudharakaP  路  3Comments

DanielFran picture DanielFran  路  3Comments

marcelinobadin picture marcelinobadin  路  3Comments