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.
Joined: Aug 07, 2003
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).