jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.55k stars 4.02k forks source link

regenerate entity cause parsing error with mapper #19216

Closed mai1015 closed 2 years ago

mai1015 commented 2 years ago
Overview of the issue

cannot regenerate entity after modify the java file

 ERROR! Error parsing file src/main/java/com/***/service/mapper/CohortMemberMapper.java: undefined

At: 1: package com.***.service.mapper;
2: 
3: 
4: 
5: import com.***.domain.CohortMember;
6: import com.***.service.dto.CohortMemberDTO;
7: 
8: import undefined.domain.User;
9: import .service.dto.UserDTO;
10: import com.***.api.domain.Cohort;
11: import com.***.api.service.dto.CohortDTO;
12: 
13: import org.mapstruct.*;
14: 
15: /**
16:  * Mapper for the entity {@link CohortMember} and its DTO {@link CohortMemberDTO}.
17:  */
18: @Mapper(componentModel = "spring")
19: public interface CohortMemberMapper extends EntityMapper<CohortMemberDTO, CohortMember> {
20:     @Mapping(target = "user", source = "user", qualifiedByName="userId")
21:     @Mapping(target = "cohort", source = "cohort", qualifiedByName="cohortId")
22:     CohortMemberDTO toDto(CohortMember s);
23: 
24: 
25:     @Named("userId")
26:     @BeanMapping(ignoreByDefault = true)
27:     @Mapping(target = "id", source = "id")
28:     UserDTO toDtoUserId(User user);
29: 
30:     @Named("cohortId")
31:     @BeanMapping(ignoreByDefault = true)
32:     @Mapping(target = "id", source = "id")
33:     CohortDTO toDtoCohortId(Cohort cohort);
34: }
35: 
Error: Error parsing file src/main/java/com/dotslive/api/service/mapper/CohortMemberMapper.java: undefined
Motivation for or Use Case

regenerate entity when edit or add extra entity

Reproduce the error

generate project then modify java file like mapper then regenerate the enetity again

Suggest a Fix

allow user to generate only specify entity or force regenerate file.

JHipster Version(s)

7.8.1

JHipster configuration
{
  "generator-jhipster": {
    "applicationType": "monolith",
    "appsFolders": ["***"],
    "authenticationType": "jwt",
    "baseName": "***",
    "blueprints": [],
    "buildTool": "maven",
    "cacheProvider": "redis",
    "clientFramework": "react",
    "clientPackageManager": "npm",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "clusteredDbApps": {},
    "creationTimestamp": 1658177084658,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "devServerPort": 9060,
    "directoryPath": "../",
    "dockerPushCommand": "docker push",
    "dockerRepositoryName": "***",
    "dtoSuffix": "DTO",
    "enableGradleEnterprise": false,
    "enableHibernateCache": true,
    "enableSwaggerCodegen": true,
    "enableTranslation": true,
    "entities": ["Cohort", "CohortMember", "Tag"],
    "entitySuffix": "",
    "ingressDomain": "",
    "istio": false,
    "jhiPrefix": "jhi",
    "jhipsterVersion": "7.8.1",
    "jwtSecretKey": "***",
    "kubernetesNamespace": "default",
    "kubernetesServiceType": "LoadBalancer",
    "kubernetesUseDynamicStorage": false,
    "languages": ["en", "zh-cn", "zh-tw"],
    "lastLiquibaseTimestamp": 1658506141000,
    "messageBroker": "kafka",
    "monitoring": "prometheus",
    "nativeLanguage": "en",
    "otherModules": [],
    "packageName": "com.***",
    "pages": [],
    "prodDatabaseType": "mysql",
    "reactive": false,
    "searchEngine": "elasticsearch",
    "serverPort": "8080",
    "serverSideOptions": ["searchEngine:elasticsearch", "messageBroker:kafka", "enableSwaggerCodegen:true"],
    "serviceDiscoveryType": false,
    "skipCheckLengthOfIdentifier": false,
    "skipFakeData": false,
    "skipUserManagement": false,
    "testFrameworks": ["cypress"],
    "websocket": false,
    "withAdminUi": true
  }
}
Entity configuration(s) entityName.json files generated in the .jhipster directory

entity Cohort {
    name String required maxlength(64)
    bio String maxlength(1024)
    categoryId Long required
    coverImageUrl String maxlength(255)
    oneLinerStatus String maxlength(255)
    organizationId Long
}

entity CohortMember(rel_cohort__users) {
    userId UUID
    cohortId Long
    roleId String
}

relationship OneToMany {
    Cohort{members} to CohortMember{cohort required}
}

relationship OneToOne {
    CohortMember{user} to User
}

paginate Cohort, CohortMember with infinite-scroll
service Cohort, CohortMember with serviceClass
dto Cohort, CohortMember with mapstruct
Tcharl commented 2 years ago

Hi,

You can add your customized classes relative path followed by the yeoman strategy you want to apply (here 'skip') to a '.yo-resolve' file located at your root of your project. It will ignore the regen next times: https://www.jhipster.tech/tips/035_tip_combine_generation_and_custom_code.html#pattern-2---split-generated-code-and-custom-code