deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karl Kildén <karl.kil...@gmail.com>
Subject Entity - DTO Mapper API question / issue
Date Wed, 11 Jun 2014 19:24:04 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message