Closed tejaswibm-roposo closed 9 months ago
Kindly note : I have redacted few details in the configurations above.
@tejaswibm-roposo Can you confirm this is related with the same issue from https://github.com/jhipster/generator-jhipster/issues/18729?
@DanielFran - I doubt its the same issue. The issue here is the way the mapperImpl are getting generated whose behaviour has changed from v7.7.0 to v7.8.1. Attaching snippets for an entity generated using the schema mentioned in the bug in both versions -
package com.inmobi.glance.brolly.service.mapper;
import com.inmobi.glance.brolly.domain.Post;
import com.inmobi.glance.brolly.service.dto.PostDTO;
import org.mapstruct.*;
/**
* Mapper for the entity {@link Post} and its DTO {@link PostDTO}.
*/
@Mapper(componentModel = "spring", uses = { AzUserMapper.class, PostAttributeMapper.class, CommentMapper.class })
public interface PostMapper extends EntityMapper<PostDTO, Post> {
@Mapping(target = "azUser", source = "azUser")
@Mapping(target = "postAttributes", source = "postAttributes")
@Mapping(target = "comments", source = "comments")
PostDTO toDto(Post s);
@Named("id")
@BeanMapping(ignoreByDefault = true)
@Mapping(target = "id", source = "id")
PostDTO toDtoId(Post post);
}
=======================================================================================================================
package com.inmobi.glance.brolly.service.mapper;
import com.inmobi.glance.brolly.domain.Comment;
import com.inmobi.glance.brolly.domain.Post;
import com.inmobi.glance.brolly.domain.PostAttribute;
import com.inmobi.glance.brolly.service.dto.PostAttributeDTO;
import com.inmobi.glance.brolly.service.dto.PostDTO;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.processing.Generated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2022-06-22T15:18:03+0530",
comments = "version: 1.4.2.Final, compiler: Eclipse JDT (IDE) 1.4.100.v20220318-0906, environment: Java 17.0.3 (Eclipse Adoptium)"
)
@Component
public class PostMapperImpl implements PostMapper {
@Autowired
private AzUserMapper azUserMapper;
@Autowired
private PostAttributeMapper postAttributeMapper;
@Override
public Post toEntity(PostDTO dto) {
if ( dto == null ) {
return null;
}
Post post = new Post();
post.setId( dto.getId() );
post.setPost( dto.getPost() );
post.setDescription( dto.getDescription() );
post.setCreatedTime( dto.getCreatedTime() );
post.setUpdatedTime( dto.getUpdatedTime() );
post.setEntityType( dto.getEntityType() );
post.setEntityId( dto.getEntityId() );
post.setViewCounter( dto.getViewCounter() );
post.azUser( azUserMapper.toEntity( dto.getAzUser() ) );
Set<Comment> set = dto.getComments();
if ( set != null ) {
post.comments( new HashSet<Comment>( set ) );
}
post.postAttributes( postAttributeDTOSetToPostAttributeSet( dto.getPostAttributes() ) );
return post;
}
@Override
public List<Post> toEntity(List<PostDTO> dtoList) {
if ( dtoList == null ) {
return null;
}
List<Post> list = new ArrayList<Post>( dtoList.size() );
for ( PostDTO postDTO : dtoList ) {
list.add( toEntity( postDTO ) );
}
return list;
}
@Override
public List<PostDTO> toDto(List<Post> entityList) {
if ( entityList == null ) {
return null;
}
List<PostDTO> list = new ArrayList<PostDTO>( entityList.size() );
for ( Post post : entityList ) {
list.add( toDto( post ) );
}
return list;
}
@Override
public void partialUpdate(Post entity, PostDTO dto) {
if ( dto == null ) {
return;
}
if ( dto.getId() != null ) {
entity.setId( dto.getId() );
}
if ( dto.getPost() != null ) {
entity.setPost( dto.getPost() );
}
if ( dto.getDescription() != null ) {
entity.setDescription( dto.getDescription() );
}
if ( dto.getCreatedTime() != null ) {
entity.setCreatedTime( dto.getCreatedTime() );
}
if ( dto.getUpdatedTime() != null ) {
entity.setUpdatedTime( dto.getUpdatedTime() );
}
if ( dto.getEntityType() != null ) {
entity.setEntityType( dto.getEntityType() );
}
if ( dto.getEntityId() != null ) {
entity.setEntityId( dto.getEntityId() );
}
if ( dto.getViewCounter() != null ) {
entity.setViewCounter( dto.getViewCounter() );
}
if ( dto.getAzUser() != null ) {
entity.azUser( azUserMapper.toEntity( dto.getAzUser() ) );
}
if ( entity.getComments() != null ) {
Set<Comment> set = dto.getComments();
if ( set != null ) {
entity.getComments().clear();
entity.getComments().addAll( set );
}
}
else {
Set<Comment> set = dto.getComments();
if ( set != null ) {
entity.comments( new HashSet<Comment>( set ) );
}
}
if ( entity.getPostAttributes() != null ) {
Set<PostAttribute> set1 = postAttributeDTOSetToPostAttributeSet( dto.getPostAttributes() );
if ( set1 != null ) {
entity.getPostAttributes().clear();
entity.getPostAttributes().addAll( set1 );
}
}
else {
Set<PostAttribute> set1 = postAttributeDTOSetToPostAttributeSet( dto.getPostAttributes() );
if ( set1 != null ) {
entity.postAttributes( set1 );
}
}
}
@Override
public PostDTO toDto(Post s) {
if ( s == null ) {
return null;
}
PostDTO postDTO = new PostDTO();
postDTO.setAzUser( azUserMapper.toDto( s.getAzUser() ) );
postDTO.setPostAttributes( postAttributeSetToPostAttributeDTOSet( s.getPostAttributes() ) );
Set<Comment> set1 = s.getComments();
if ( set1 != null ) {
postDTO.setComments( new HashSet<Comment>( set1 ) );
}
postDTO.setId( s.getId() );
postDTO.setPost( s.getPost() );
postDTO.setDescription( s.getDescription() );
postDTO.setCreatedTime( s.getCreatedTime() );
postDTO.setUpdatedTime( s.getUpdatedTime() );
postDTO.setEntityType( s.getEntityType() );
postDTO.setEntityId( s.getEntityId() );
postDTO.setViewCounter( s.getViewCounter() );
return postDTO;
}
@Override
public PostDTO toDtoId(Post post) {
if ( post == null ) {
return null;
}
PostDTO postDTO = new PostDTO();
postDTO.setId( post.getId() );
return postDTO;
}
protected Set<PostAttribute> postAttributeDTOSetToPostAttributeSet(Set<PostAttributeDTO> set) {
if ( set == null ) {
return null;
}
Set<PostAttribute> set1 = new HashSet<PostAttribute>( Math.max( (int) ( set.size() / .75f ) + 1, 16 ) );
for ( PostAttributeDTO postAttributeDTO : set ) {
set1.add( postAttributeMapper.toEntity( postAttributeDTO ) );
}
return set1;
}
protected Set<PostAttributeDTO> postAttributeSetToPostAttributeDTOSet(Set<PostAttribute> set) {
if ( set == null ) {
return null;
}
Set<PostAttributeDTO> set1 = new HashSet<PostAttributeDTO>( Math.max( (int) ( set.size() / .75f ) + 1, 16 ) );
for ( PostAttribute postAttribute : set ) {
set1.add( postAttributeMapper.toDto( postAttribute ) );
}
return set1;
}
}
package com.inmobi.glance.brolly.service.mapper;
import com.inmobi.glance.brolly.domain.AzUser;
import com.inmobi.glance.brolly.domain.Post;
import com.inmobi.glance.brolly.service.dto.AzUserDTO;
import com.inmobi.glance.brolly.service.dto.PostDTO;
import org.mapstruct.*;
/**
* Mapper for the entity {@link Post} and its DTO {@link PostDTO}.
*/
@Mapper(componentModel = "spring")
public interface PostMapper extends EntityMapper<PostDTO, Post> {
@Mapping(target = "azUser", source = "azUser", qualifiedByName = "azUserId")
PostDTO toDto(Post s);
@Named("azUserId")
@BeanMapping(ignoreByDefault = true)
@Mapping(target = "id", source = "id")
AzUserDTO toDtoAzUserId(AzUser azUser);
}
=======================================================================================
package com.inmobi.glance.brolly.service.mapper;
import com.inmobi.glance.brolly.domain.AzUser;
import com.inmobi.glance.brolly.domain.Dashboard;
import com.inmobi.glance.brolly.domain.Doc;
import com.inmobi.glance.brolly.domain.Portal;
import com.inmobi.glance.brolly.domain.Post;
import com.inmobi.glance.brolly.domain.Schema;
import com.inmobi.glance.brolly.service.dto.AzUserDTO;
import com.inmobi.glance.brolly.service.dto.DashboardDTO;
import com.inmobi.glance.brolly.service.dto.DocDTO;
import com.inmobi.glance.brolly.service.dto.PortalDTO;
import com.inmobi.glance.brolly.service.dto.PostDTO;
import com.inmobi.glance.brolly.service.dto.SchemaDTO;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.processing.Generated;
import org.springframework.stereotype.Component;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2022-06-22T15:24:21+0530",
comments = "version: 1.4.2.Final, compiler: Eclipse JDT (IDE) 1.4.100.v20220318-0906, environment: Java 17.0.3 (Eclipse Adoptium)"
)
@Component
public class PostMapperImpl implements PostMapper {
@Override
public Post toEntity(PostDTO dto) {
if ( dto == null ) {
return null;
}
Post post = new Post();
post.setId( dto.getId() );
post.setPost( dto.getPost() );
post.setDescription( dto.getDescription() );
post.setCreatedTime( dto.getCreatedTime() );
post.setUpdatedTime( dto.getUpdatedTime() );
post.setEntityType( dto.getEntityType() );
post.setEntityId( dto.getEntityId() );
post.setViewCounter( dto.getViewCounter() );
post.azUser( azUserDTOToAzUser( dto.getAzUser() ) );
return post;
}
@Override
public List<Post> toEntity(List<PostDTO> dtoList) {
if ( dtoList == null ) {
return null;
}
List<Post> list = new ArrayList<Post>( dtoList.size() );
for ( PostDTO postDTO : dtoList ) {
list.add( toEntity( postDTO ) );
}
return list;
}
@Override
public List<PostDTO> toDto(List<Post> entityList) {
if ( entityList == null ) {
return null;
}
List<PostDTO> list = new ArrayList<PostDTO>( entityList.size() );
for ( Post post : entityList ) {
list.add( toDto( post ) );
}
return list;
}
@Override
public void partialUpdate(Post entity, PostDTO dto) {
if ( dto == null ) {
return;
}
if ( dto.getId() != null ) {
entity.setId( dto.getId() );
}
if ( dto.getPost() != null ) {
entity.setPost( dto.getPost() );
}
if ( dto.getDescription() != null ) {
entity.setDescription( dto.getDescription() );
}
if ( dto.getCreatedTime() != null ) {
entity.setCreatedTime( dto.getCreatedTime() );
}
if ( dto.getUpdatedTime() != null ) {
entity.setUpdatedTime( dto.getUpdatedTime() );
}
if ( dto.getEntityType() != null ) {
entity.setEntityType( dto.getEntityType() );
}
if ( dto.getEntityId() != null ) {
entity.setEntityId( dto.getEntityId() );
}
if ( dto.getViewCounter() != null ) {
entity.setViewCounter( dto.getViewCounter() );
}
if ( dto.getAzUser() != null ) {
if ( entity.getAzUser() == null ) {
entity.azUser( new AzUser() );
}
azUserDTOToAzUser1( dto.getAzUser(), entity.getAzUser() );
}
}
@Override
public PostDTO toDto(Post s) {
if ( s == null ) {
return null;
}
PostDTO postDTO = new PostDTO();
postDTO.setAzUser( toDtoAzUserId( s.getAzUser() ) );
postDTO.setId( s.getId() );
postDTO.setPost( s.getPost() );
postDTO.setDescription( s.getDescription() );
postDTO.setCreatedTime( s.getCreatedTime() );
postDTO.setUpdatedTime( s.getUpdatedTime() );
postDTO.setEntityType( s.getEntityType() );
postDTO.setEntityId( s.getEntityId() );
postDTO.setViewCounter( s.getViewCounter() );
return postDTO;
}
@Override
public AzUserDTO toDtoAzUserId(AzUser azUser) {
if ( azUser == null ) {
return null;
}
AzUserDTO azUserDTO = new AzUserDTO();
azUserDTO.setId( azUser.getId() );
return azUserDTO;
}
protected Portal portalDTOToPortal(PortalDTO portalDTO) {
if ( portalDTO == null ) {
return null;
}
Portal portal = new Portal();
portal.setId( portalDTO.getId() );
portal.setName( portalDTO.getName() );
portal.setUrl( portalDTO.getUrl() );
portal.setDescription( portalDTO.getDescription() );
portal.setOwner( portalDTO.getOwner() );
portal.setTags( portalDTO.getTags() );
portal.setStatus( portalDTO.getStatus() );
portal.setUnitType( portalDTO.getUnitType() );
portal.setWindow( portalDTO.getWindow() );
portal.setHealth( portalDTO.getHealth() );
portal.setComment( portalDTO.getComment() );
portal.setIconSrc( portalDTO.getIconSrc() );
return portal;
}
protected Set<Portal> portalDTOSetToPortalSet(Set<PortalDTO> set) {
if ( set == null ) {
return null;
}
Set<Portal> set1 = new HashSet<Portal>( Math.max( (int) ( set.size() / .75f ) + 1, 16 ) );
for ( PortalDTO portalDTO : set ) {
set1.add( portalDTOToPortal( portalDTO ) );
}
return set1;
}
protected Dashboard dashboardDTOToDashboard(DashboardDTO dashboardDTO) {
if ( dashboardDTO == null ) {
return null;
}
Dashboard dashboard = new Dashboard();
dashboard.setId( dashboardDTO.getId() );
dashboard.setName( dashboardDTO.getName() );
dashboard.setUrl( dashboardDTO.getUrl() );
dashboard.setDescription( dashboardDTO.getDescription() );
dashboard.setOwner( dashboardDTO.getOwner() );
dashboard.setTags( dashboardDTO.getTags() );
dashboard.setStatus( dashboardDTO.getStatus() );
dashboard.setUnitType( dashboardDTO.getUnitType() );
dashboard.setWindow( dashboardDTO.getWindow() );
dashboard.setComment( dashboardDTO.getComment() );
dashboard.setVideoUrl( dashboardDTO.getVideoUrl() );
dashboard.setIconSrc( dashboardDTO.getIconSrc() );
dashboard.setViewCounter( dashboardDTO.getViewCounter() );
return dashboard;
}
protected Set<Dashboard> dashboardDTOSetToDashboardSet(Set<DashboardDTO> set) {
if ( set == null ) {
return null;
}
Set<Dashboard> set1 = new HashSet<Dashboard>( Math.max( (int) ( set.size() / .75f ) + 1, 16 ) );
for ( DashboardDTO dashboardDTO : set ) {
set1.add( dashboardDTOToDashboard( dashboardDTO ) );
}
return set1;
}
protected Doc docDTOToDoc(DocDTO docDTO) {
if ( docDTO == null ) {
return null;
}
Doc doc = new Doc();
doc.setId( docDTO.getId() );
doc.setName( docDTO.getName() );
doc.setUrl( docDTO.getUrl() );
doc.setDescription( docDTO.getDescription() );
doc.setOwner( docDTO.getOwner() );
doc.setTags( docDTO.getTags() );
doc.setStatus( docDTO.getStatus() );
doc.setUnitType( docDTO.getUnitType() );
doc.setWindow( docDTO.getWindow() );
doc.setComment( docDTO.getComment() );
doc.setIconSrc( docDTO.getIconSrc() );
return doc;
}
protected Set<Doc> docDTOSetToDocSet(Set<DocDTO> set) {
if ( set == null ) {
return null;
}
Set<Doc> set1 = new HashSet<Doc>( Math.max( (int) ( set.size() / .75f ) + 1, 16 ) );
for ( DocDTO docDTO : set ) {
set1.add( docDTOToDoc( docDTO ) );
}
return set1;
}
protected Schema schemaDTOToSchema(SchemaDTO schemaDTO) {
if ( schemaDTO == null ) {
return null;
}
Schema schema = new Schema();
schema.setId( schemaDTO.getId() );
schema.setName( schemaDTO.getName() );
schema.setUnitType( schemaDTO.getUnitType() );
return schema;
}
protected Set<Schema> schemaDTOSetToSchemaSet(Set<SchemaDTO> set) {
if ( set == null ) {
return null;
}
Set<Schema> set1 = new HashSet<Schema>( Math.max( (int) ( set.size() / .75f ) + 1, 16 ) );
for ( SchemaDTO schemaDTO : set ) {
set1.add( schemaDTOToSchema( schemaDTO ) );
}
return set1;
}
protected AzUser azUserDTOToAzUser(AzUserDTO azUserDTO) {
if ( azUserDTO == null ) {
return null;
}
AzUser azUser = new AzUser();
azUser.setId( azUserDTO.getId() );
azUser.setUserGuid( azUserDTO.getUserGuid() );
azUser.setFirstName( azUserDTO.getFirstName() );
azUser.setLastName( azUserDTO.getLastName() );
azUser.setEmail( azUserDTO.getEmail() );
azUser.setStatus( azUserDTO.getStatus() );
azUser.portals( portalDTOSetToPortalSet( azUserDTO.getPortals() ) );
azUser.dashboards( dashboardDTOSetToDashboardSet( azUserDTO.getDashboards() ) );
azUser.docs( docDTOSetToDocSet( azUserDTO.getDocs() ) );
azUser.schemata( schemaDTOSetToSchemaSet( azUserDTO.getSchemata() ) );
return azUser;
}
protected void azUserDTOToAzUser1(AzUserDTO azUserDTO, AzUser mappingTarget) {
if ( azUserDTO == null ) {
return;
}
if ( azUserDTO.getId() != null ) {
mappingTarget.setId( azUserDTO.getId() );
}
if ( azUserDTO.getUserGuid() != null ) {
mappingTarget.setUserGuid( azUserDTO.getUserGuid() );
}
if ( azUserDTO.getFirstName() != null ) {
mappingTarget.setFirstName( azUserDTO.getFirstName() );
}
if ( azUserDTO.getLastName() != null ) {
mappingTarget.setLastName( azUserDTO.getLastName() );
}
if ( azUserDTO.getEmail() != null ) {
mappingTarget.setEmail( azUserDTO.getEmail() );
}
if ( azUserDTO.getStatus() != null ) {
mappingTarget.setStatus( azUserDTO.getStatus() );
}
if ( mappingTarget.getPortals() != null ) {
Set<Portal> set = portalDTOSetToPortalSet( azUserDTO.getPortals() );
if ( set != null ) {
mappingTarget.getPortals().clear();
mappingTarget.getPortals().addAll( set );
}
}
else {
Set<Portal> set = portalDTOSetToPortalSet( azUserDTO.getPortals() );
if ( set != null ) {
mappingTarget.portals( set );
}
}
if ( mappingTarget.getDashboards() != null ) {
Set<Dashboard> set1 = dashboardDTOSetToDashboardSet( azUserDTO.getDashboards() );
if ( set1 != null ) {
mappingTarget.getDashboards().clear();
mappingTarget.getDashboards().addAll( set1 );
}
}
else {
Set<Dashboard> set1 = dashboardDTOSetToDashboardSet( azUserDTO.getDashboards() );
if ( set1 != null ) {
mappingTarget.dashboards( set1 );
}
}
if ( mappingTarget.getDocs() != null ) {
Set<Doc> set2 = docDTOSetToDocSet( azUserDTO.getDocs() );
if ( set2 != null ) {
mappingTarget.getDocs().clear();
mappingTarget.getDocs().addAll( set2 );
}
}
else {
Set<Doc> set2 = docDTOSetToDocSet( azUserDTO.getDocs() );
if ( set2 != null ) {
mappingTarget.docs( set2 );
}
}
if ( mappingTarget.getSchemata() != null ) {
Set<Schema> set3 = schemaDTOSetToSchemaSet( azUserDTO.getSchemata() );
if ( set3 != null ) {
mappingTarget.getSchemata().clear();
mappingTarget.getSchemata().addAll( set3 );
}
}
else {
Set<Schema> set3 = schemaDTOSetToSchemaSet( azUserDTO.getSchemata() );
if ( set3 != null ) {
mappingTarget.schemata( set3 );
}
}
}
}
I have upgraded JHipster already. Hence, not able to get earlier version of generated mapperImpl.
Question - Why is 1-n mapping of entity not being mapped in dto
and mapperImpl
. Ex: PostAttributes
and Comments
set ? In v7.7.0, this was handled as expected.
This issue is stale because it has been open for too long without any activity. Due to the moving nature of jhipster generated application, bugs can become invalid. If this issue still applies please comment otherwise it will be closed in 7 days
JHipster has completed the sample check
.yo-rc.json
: valid
Entities JDL: error
Application:
Frontend check: skipped
Backend check: skipped
E2E check: skipped
This check uses jhipster info
output from the issue description to generate the sample.
Bug report that does not contain this information will be marked as invalid.
Sample is missing information, cannot be reproduced. Fixes for cyclic relationships landed in https://github.com/jhipster/generator-jhipster/pull/24746. Closing.
Overview of the issue
I had generated JHipster - React app with v7.7.0. Now, I have upgraded it to v7.8.1 based on the documentation here by running
npx jhipster upgrade
command.This re-generated the mapper classes from JPA to DTO.
The generated mapper classes in v7.8.1 are different from those generated with version v7.7.0 and there is a cyclic method calls getting generated which were not present in v7.7.0.
Motivation for or Use Case
Due to cyclic method calls, SO error is getting thrown from the server.
Reproduce the error
Generate entities as given in the jdl below.
Related issues
Suggest a Fix
Not Sure. Maybe revert mapper generator to the same as provided in v7.7.0
JHipster Version(s)
7.8.1
JHipster configuration
app └── generator-jhipster@7.8.1
Entity configuration(s)
entityName.json
files generated in the.jhipster
directoryJDL definitions
Browsers and Operating System
MacOS 12.3.1. Issue is not browser specific.