Is there any guidelines that help decide which tables need to be entity beans?
- Posted by: Badri S
- Posted on: September 15 2000 05:26 EDT
- Design Guidelines for Entity Beans by Floyd Marinescu on September 18 2000 10:36 EDT
- Design Guidelines for Entity Beans by Badri S on September 19 2000 05:42 EDT
- Design Guidelines for Entity Beans by Roger Cornejo on September 19 2000 16:58 EDT
The usual mapping is one table = one entity bean.
Thanks. I would like to know if this mapping is a must? Or, are there guidelines to determine if a table qualifies to be an entity bean.
An entity must have a unique identification (the PK) and should (almost always) have a lifetime which is independent of other entities. I consider an Invoice and a Product an entity and an InvoiceLine to be a dependent object of the Invoice entity that references a Product entity.
Many of the standard CMP facilities in EJB servers only allow a single row, table-per-entity mapping. I tend to ignore this restriction and either use more powerful containers (WLS with TOPLink, Gemstone/J, etc.) and design my entities accordingly. If you needed to deploy one of my beans on a more limited environment you'd have to create a subclass that was a BMP entity.
We have actually had some success mapping one Entity bean to a view in Oracle; this view combines many tables, and has a PK. It is for read only queries, but is a great way to get aggregated data with one bean. For writing back to the DB, we simply write to each table independently, through individual entity beans.
Refer to The Java 2 Enterprise Edition Developer's Guide, Chapter 9 Advanced Topics (page 135). It helped me clear out most of the doubts I had about mapping entity beans to the relational model, from One-to-One relationships to Many-to-Many relationships. You can download the document freely from the java.sun.com site.
An article by Craig Larman, "Enterprise JavaBeans 201: The Aggregate Entity Pattern", from Software Development Magazine, April 2000, may be of interest.
There are some useful thoughts on deciding what to make an entity bean.
all views are mine ...