-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: DTO or not DTO
PostPosted: Wed Jan 21, 2004 3:45 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Hi,

Here is a small example where DTO seems to be useful. I would like to have some feedback on how to do this without DTO.
I have a User and Profile classes. One User can have multiple Profile.
Code:
public class User
{
    private List listOfProfile;
}

I have a common architecture. A domain layer made of BO (Hibernate independent) + DAO (hibernate dependent). On top of that, I have a service layer made of services that communicates with the presentation layer (Struts like) with DTOs.
To add a Profile to a User I have to check if there is enough licences. In my point of view this check occurs in the service layer.
To modify the User"s profiles I have a service like
Code:
public class UserService
{
    public UserDTO getUser(String userID);
    public UserDTO modifyUser(UserDTO user);
    public UserDTO modifyUserProfiles(UserDTO user);
}

With this service, I can ensure that my presentation layer must go through the 'modifyUserProfiles' method to modify the user profiles (because in the modifyUser method I don't care about any profiles modification).
Now without my DTOs I would have a service like this
Code:
public class UserService
{
    public User getUser(String userID);
    public User modifyUser(User user);
    public User modifyUserProfiles(User user);
}

If I want to add some profiles to a user, in the presentation layer I can do :
Code:
User user = userService.getUser("myId");
user.getListOfProfiles().add(aProfile);
userService.modifyUser(user);

with Hibernate's transitive persistence mechanism, the profile is added to the User without any licence check.
As this is a service level check, I don't want to use any of the Hibernate tricks (interceptors for example) to do that. I want to do it in an Hibernate independent way.
So, is there a way to achieve my goal without the use of DTOs

Thanx, Seb


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 9:25 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Loading user and compare with the transient version of your BO in your service layer ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 11:29 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
But it does not ensure that the presentation developer won't bypass my service method as I mentionned in my last code snippet


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 11:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Pretty much the same problem was discussed in this thread, probably take a look at it. http://forum.hibernate.org/viewtopic.php?t=926778&start=0


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 11:44 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
gloeglm wrote:
Pretty much the same problem was discussed in this thread, probably take a look at it. http://forum.hibernate.org/viewtopic.php?t=926778&start=0

Not sure this is the same problem (but it is something related. The thread you mentionned try to state where to check for unicity constraint and how to organize the domain level.
My main problem here is how to communicate between service layer and presentation layer. Gavin on is JAOO presentation said that DTO are evil and are not useful. As I find a use case where they seem to be useful I just want to have some advices on how to achieve the same goal without DTOs


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 12:29 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Validatable interface or interceptor is done for that but you don't want to pollute BO with business process rules

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.