aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Java Beans VS Data Transfer 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 "Java Beans VS Data Transfer Objects" Watch "Java Beans VS Data Transfer Objects" New topic
Author

Java Beans VS Data Transfer Objects

Sajee Joseph
Ranch Hand

Joined: Jan 17, 2001
Posts: 200
Hello all,
Whats the difference between Java Beans VS Data Transfer Objects.
Are both the same or is one a superset of another.
Please note that im referring to Java Beans and not EJBs.
Thanks,
Saj
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Data Transfer object is a java bean which is transported across tier i.e. from presentation tier and EJB tier and vice versa.


Groovy
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Sajee Joseph:
Whats the difference between Java Beans VS Data Transfer Objects.

An entity EJB is a Java class that maps to a persistence framework, typically some form of object-relational mapping tool or directly through your container. Being an EJB, it uses the container to access services like persistence, transactions, security, and the like. You should not normally access entity beans directly from your client application but rather through a session beans.
Typically in the presentation layer you need a different set of data about an entity bean -- either a subset or maybe a grouping of several beans together. The Data Transfer Object pattern is used here as a light-weight method of transfering the data you need between the two layers. Another example is value objects generated by XDoclet. These objects don't have any clue as to persistence, security, or transactions. They are simple collections of data -- you could use a Map or JavaBean or your own framework.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Sajee Joseph:
Please note that im referring to Java Beans and not EJBs.

Originally posted by me:
An entity EJB ...

Yeah, space cadet, sorry.
To actually answer your question, a DTO is a pattern while a JavaBean is a specification. To be a JavaBean, your class must conform to a contract: a no-argument constructor and getters/setters for the attributes. A DTO is a pattern for shuttling data from various sources between your application layers (or across a network or whatever). You could use a JavaBean to implement the DTO pattern, or you could use something else (my DTO is based on a simple Map of fields without named accessors).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Beans VS Data Transfer Objects