You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@deltaspike.apache.org by Karl Kildén <ka...@gmail.com> on 2014/06/11 21:24:04 UTC
Entity - DTO Mapper API question / issue
Hi guys this regards the mapping API and
https://issues.apache.org/jira/browse/DELTASPIKE-606
So I ran into issues with the DTO mapper api and voiced my concerns in irc.
I saw the discussion and now I am trying the solution present in the
current SNAPSHOT. However I have one comment / question:
What if my Entity has a relationship to another Entity?
Like this:
public class User extends BaseAuditEntity {
@Column
private String name;
@Column
@ManyToOne
@JoinColumn(name="group_id")
private Group group;
This means my userDTO may come with a GroupDTO and how do I map that
relationship? Or to explain by code please fill in the question marks below
;) or if you feel my implementation is weird then I would gladly accept
comments on that too. But the way I see it I need to @Inject the
GroupMapper, use the EntityManager to find the Group then call
groupMapper.toEntity and then I think to myself that the API is worse now
because before I could call groupMapper.toEntity with only a dto argument.
At that point you had to use the entitymanager anyways to find "yourself"
and that feels clean compared to find your entities you form relationships
with.
@Override
protected User toEntity(final User user, final UserDTO userDTO) {
MapperUtil.toAuditEntity(user, userDTO);
user.setName(userDTO.getName());
user.setEmail(userDTO.getEmail());
user.setLocale(userDTO.getLocale());
user.setGroup(*?????*);
return user;
}
Cheers / Karl