This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Regarding Entity beans and value objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Regarding Entity beans and value objects" Watch "Regarding Entity beans and value objects" New topic

Regarding Entity beans and value objects

prabhu gupte

Joined: Nov 28, 2004
Posts: 4
Hi All,
How do Entity beans differ from value objects. Excluding the differences that entity beans run inside a EJB Container and the various services that the container provides to them.
As far as i know the value objects are just plain and simple java objects containing set and get methods for each of their attributes and do not contain any SQL inside any of the methods which a Entity bean(BMP) may have.
The similarity is that both have getter and setter methods.
I need to clarify myself whether value objects can be a replacement for Entity beans. If that is not the case then, can both work in collaboration and if yes then how.
What scenarios can really force one to adopt the value objects as part of the solution.
prabhu gupte

Joined: Nov 28, 2004
Posts: 4
Isn't it that the FormBeans that are part of Struts Framework behave like value objects since, apart from being a grab bag of all the related fields inside the FormBean they also have certain validations to make sure the fields that are part of the FormBean are valid as per business rules. Also value object pattern recommends its use only when two layers need lot of data to be exchanged between them and theres a need to keep this transfer manageable. Related pieces of data can be clubbed in to a single VO and method calls can then use these VO as arguments.
Am i right?
Peter Rooke
Ranch Hand

Joined: Oct 21, 2004
Posts: 810

"Am i right?" - Yes, VO (or transfer objects) can improve the design of a system, and tend to be used with EJB's. A few advantages: Reduce network traffic, transfer more data in fewer remote calls (etc) - It's a J2EE dedign pattern; google will provide you with much more.
Core J2EE Patterns - Transfer Object.

"two layers need lot of data to be exchanged between them" - yes, can produce cleaner code, if used in the same layer (IMHO).

Also, have a look at the Hibenate / JDO frameworks (their is forum on JavaRanch). Lastly you should know that the new EJB3 specification is going to make things a lot simpler (thankfully!).

Regards Pete
Ghulam Rashid
Ranch Hand

Joined: Jan 14, 2002
Posts: 278
Using VO insures Course Granied rather than Fine-Grained, with lot of advantages as discussed above.
Course grained is one large object to do many things.
Fine grained is spreading those responsibilities among many smaller classes.

Have you checked out Aspose?
subject: Regarding Entity beans and value objects
It's not a secret anymore!