File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes EJB Design With 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 "EJB Design With Value Objects" Watch "EJB Design With Value Objects" New topic

EJB Design With Value Objects

Greg Nudelman

Joined: Feb 25, 2002
Posts: 2
Dear EJB Gurus:
I have an EJB system with a HashMap-driven customization interface on the web-tier (That is I ultimately need to persent a HashMap of Strings values to my JSP for display).
Because of the badly coded EJBs, I had a need to create a fairly large (100 attributes, representing 5 DB tables) value object (VO) to validate and massage the complete incoming data. I then use this VO to set my Entity EJBs under the wrapping of a Session EJB. This leaves me a with a large VO on the EJB server and a HashMap that needs to be displayed on the client. Incoming data is of course unformated, and the dat that needs to be displayed from the HashMap needs to be formated. the formating logic is inside the VO.
incoming -> display
"1" -> "Books"
"1000" -> $1,000.00"

I have the following choices (assuming success of all operations):
1) Communicate via VOs:
Collect data, create a VO, and validate, all on the web tier. Then pass this valid VO to the EJB tier to save in the DB. [Optional: Return a new VO to the web tier that resulted from integrating the data.]
Get a VO from the EJB, then use this VO on the Web tier to produce a formated display view HashMap and display it.
2) Communicate via HashMaps:
Collect data in the HashMap structure on the web tier, then pass that structure without validation to the EJB tier. On the EJB tier: construct VO, validate, pass VO to the Entity Beans, and save to DB. Then use this same VO to produce a formated display view HashMap and send it to the Web tier for display.
I have a "Core J2EE Patterns" book, but it describes VOs that are very light and just hold the data (So in my case HashMap acts like this). VOs do not massage data, translate it or validate it, nor present it for display. This is what the EJB Business methods supposed to do.
I want this to be squeaky-clean since I'm re-doing a lot of bad code already. Any thoughts would be greatly appreciated.

I'm alergic to Mondays
Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
IMO VO are made to avoid the expensive remote calls. Also VO must be handled carefully since they have to be insync with the beans so that they dont become dirty.
If the VO is very big (megs?) IMO i dont think it may be worth to use VO to begin with ,considering the network bandwith
I agree. Here's the link:
subject: EJB Design With Value Objects
It's not a secret anymore!