问题
Objective
My objective is to merge UI Object from presentation layer to Persistence Object at persistence layer. (DetachCopy and Update using JDO)
Detail
Want to merge UIObject to Persistence object without loosing other states of persistence object. I had tested the use case with Orika. It successfully merged outer objects, but for internal objects its creating new objects. So I am loosing the persistence states of persistence object, actually sets by persistence layer.
Complexity
Outer FXUser object contains an inner object ChildMetaData. ChildMetaData object contains list of outer FXUser object. At any level, object exist, need to merge else need to add. If source internal list does't have an object, it need to be removed from desitination. Equals and Hash code is overrided with unique value.
MapperFactory factory = new DefaultMapperFactory.Builder().build();
BoundMapperFacade<FXUserTO, FXUserVO> mapper =
factory.getMapperFacade(FXUserTO.class, FXUserVO.class);
mapper.map(sourceFxTO, destinationFxVO);
My Object structure give below and
My Object Structure
Persistence Object
public class FXUserVO implements TalosVO {
private int userId;
private ChildMetaDataVO childMetaData;
.......other fields
..... getters and setters
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + userId;
return result;
}
@Override public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FXUserVO other = (FXUserVO) obj;
if (userId != other.userId)
return false;
return true;
}
}
public class ChildMetaDataVO implements TalosVO {
private List<FXUserVO> childUsers;
.......other fields
..... getters and setters
}
Corresponding UI Object
public class FXUserTO implements TalosTO {
private int userId;
private ChildMetaDataTO childMetaData;
.......other fields
..... getters and setters
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + userId;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FXUserTO other = (FXUserTO) obj;
if (userId != other.userId)
return false;
return true;
}
}
public class ChildMetaDataTO implements TalosTO {
private List<FXUserTO> childUsers;
.......other fields
..... getters and setters
}
来源:https://stackoverflow.com/questions/43275861/will-orika-map-complex-object-having-recursive-structure