-->
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.  [ 2 posts ] 
Author Message
 Post subject: POJO and Value Object pattern
PostPosted: Mon Jul 26, 2004 10:01 am 
Beginner
Beginner

Joined: Thu Oct 09, 2003 11:41 am
Posts: 39
Location: Paris, France
Hello,

We're using Hibernate POJOs instead of Entity Beans in some places in our architecture. I was wondering, what would be the correct way to create Value Objects.
Is it approapriate to extend a POJO and use that as the value object? For example,

Code:
// POJO
public class User implements Serializable
{
    //  persistent fields
    private String login;
    private String password;
     // getters/setters
.............
    // getters/setters for the Value Object
    public getVO()
    {
              UserVO vo = new UserVO();
              vo.setLogin(getLogin());
              vo.setPassword(getPassword());
               //other fields
               return vo;
    }
    public setVO(UserVO vo)
     {
         setLogin(vo.getLogin());
         setPassword(vo.getPassword());
     }

}

//Value Object, and IUser is the business interface
public class UserVO extends User implements IUser
{

}

public interface IUser
{
//list of persistent getters/setters
}


The Value Objects generally contain stale data if EntityBean are used, but with Hibernate they always contain up-to-date data (as we simply extend a POJO) The side-effect of this means that the object is directly mapped to the DB, so setting a property of a value object may eventually alter the record in the DB, which we don't want, as this is supposed to be a value object, not a POJO. How to prevent this from happening?

Maybe, I shouldn't worry too much about this, as VO is not actually mapped to the DB, although POJO is. And once VO is not mapped, ti should be no problem changing its properties.

In which cases and under which circumstances will DB get updated if the client is using the VO?

Anyonce could shed some light?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 11:45 am 
Beginner
Beginner

Joined: Wed Jun 23, 2004 12:37 pm
Posts: 20
closing your Hib' session detaches the object from the database. So then you can call as many setters as you wish without it affecting the row that the data came from.

Cheers

Nick


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.