Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to implement EntityBean as Value Object?  RSS feed

Stephen Lee
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used session facade in my project. A session bean lookups an entity bean for the getting / setting of the data. However, there are more than 20 variables in the entity bean, that means I have used more than 20 setxxx or getxxx methods for a record in the session bean. I know this increase the database traffic, so I try to use value object pattern in my entity bean. However, I met difficulties to create the entity bean as value object. I can't find any detailed source code for this --
for example,
the code of the value object:
public class PartsVO implements {
public String partsID, partsName, desc;

public PartsVO(PartsVO parts) {
init(parts.partsID, parts.partsName, parts.desc;
public void init(String partsID, String partsName, Strign desc) {
this.partsID = partsID;
this.partsName = partsName;
this.desc = desc;

public PartsVO getData() {
return new PartsVO(this);
1) In this case, the entity bean subclasses the value object. How should I implement the entity bean (PartsDataBean)?
public class PartsDataBean extends PartsVO implements javax.ejb.EntityBean {
EntityContext entityContext;
public PartsDataPK ejbCreate(String projID) throws CreateException {
// how should I implement here?
public void ejbPostCreate(String projID) throws CreateException {
// other ejb methods
// should I need the following code?
public abstract void setProjID(String projID);
public abstract String getProjID();
public abstract void setProjName(String projName);
public abstract String getProjName();
public abstract void setDesc(String desc);
public abstract String getDesc();

2) How about the PartsData and PartsDataHome?
3) Moreover, there are some finder methods in the bean... is there any difference to implement it?
Mat Robinson
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you want to be doing is using a Value Object inside the Entity Bean not as an Entity Bean.
The Value Object is then set and get on the entity bean using a single call eg. setData(ValueObject obj) { ... }. This then puts all the values into the bean in a single hit.
From then on, it depends whether you are using CMP or BMP in your entity as to where to go.
Check out the Java Blueprints on
Hope this helps,
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!