You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using MapStruct to map between JPA entities and POJO DTOs.
All my entities extend a common base class that has an ID field (a java.lang.Long).
I have the following abstract mapper, that allows me to map from relationship in JPA to a simple Long field (or List) in the DTOs.
An entity or List<entity> field can be mapped to a Long/List<Long> field, e.g. User.groups could be mapped to UserDTO.groupIds :
@Mapper
public abstract class EntityMapper {
public Long entityToLongId(AbstractBaseEntity entity){
return entity.getId();
}
public abstract List<Long> entityCollectionToLongIdList(Collection<? extends AbstractBaseEntity> entities);
}
However the generated implementation class does not include any import statement for the AbstractBaseEntity class, although it is present in the abstract class, so the code does not compile :
package ....;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.Generated;
import org.springframework.stereotype.Component;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2016-07-27T12:11:25+0200",
comments = "version: 1.0.0.Final, compiler: javac, environment: Java 1.8.0_66 (Oracle Corporation)"
)
@Component
public class EntityMapperImpl extends EntityMapper {
@Override
public List<Long> entityCollectionToLongIdList(Collection<? extends ch.unine.tango.model.AbstractBaseEntity> entities) {
if ( entities == null ) {
return null;
}
List<Long> list = new ArrayList<Long>();
for ( AbstractBaseEntity abstractBaseEntity : entities ) { // compilation error here !
list.add( entityToLongId( abstractBaseEntity ) );
}
return list;
}
}
I am using MapStruct 1.0.0.Final with Java 8.
If I add an abstract method that uses the AbstractBaseEntity class directly, then the import is added :
public abstract AbstractBaseEntityDTO entityToDTO(AbstractBaseEntity abstractBaseEntity);
The text was updated successfully, but these errors were encountered:
That's not good. I'm almost sure we didn't fix anything in that area after 1.0.0.Final, but just in case: could you please try it with the latest 1.1.0.Beta2 as well? Thanks!
This is actually fixed in 1.1.0.Beta2, the import is created.
So, I'll leave the explicit method for now as a workaround although I don't otherwise need it, and I will switch to 1.1.0 as soon as it hits production status.
I already posted a question on StackOverflow : http://stackoverflow.com/questions/38610306/why-does-this-mapstruct-generated-class-does-not-include-import-statement
I am using MapStruct to map between JPA entities and POJO DTOs.
All my entities extend a common base class that has an ID field (a
java.lang.Long
).I have the following abstract mapper, that allows me to map from relationship in JPA to a simple Long field (or List) in the DTOs.
An entity or
List<entity>
field can be mapped to aLong
/List<Long>
field, e.g.User.groups
could be mapped toUserDTO.groupIds
:However the generated implementation class does not include any import statement for the
AbstractBaseEntity
class, although it is present in the abstract class, so the code does not compile :I am using MapStruct 1.0.0.Final with Java 8.
If I add an abstract method that uses the
AbstractBaseEntity
class directly, then the import is added :public abstract AbstractBaseEntityDTO entityToDTO(AbstractBaseEntity abstractBaseEntity);
The text was updated successfully, but these errors were encountered: