dcsimg
Multitable Mapping of a CMP 2.0 Entity Bean
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Steven_Rose
Posted On:   Tuesday, June 11, 2002 08:23 AM

In O'Reilly publishers "Enterprise JavaBeans" by Richard Monson-Haefel, Chapter 3 under the heading "Persistence": Frequently, bean types will map to more than one table [in the database]. These are more complicated mappings, often requiring an SQL join. Good EJB deployment tools should provide wizards that make multitable mappings fairly easy. Let's assume for the sake of a simple example that I have two tables in the DB with a one-to-one mapping, NAME and SOCIAL_SECURITY. NAME has three columns: id (primary key), first, and last. SOCIAL_SECURITY has two: id (primary key), and ssn. I want a single entity bean to represent first name, last name, and SSN. According to the above passage, I should be able to map firs   More>>

In O'Reilly publishers "Enterprise JavaBeans" by Richard Monson-Haefel, Chapter 3 under the heading "Persistence":



Frequently, bean types will map to more than one table [in the database]. These are more complicated mappings, often requiring an SQL join. Good EJB deployment tools should provide wizards that make multitable mappings fairly easy.


Let's assume for the sake of a simple example that I have two tables in the DB with a one-to-one mapping, NAME and SOCIAL_SECURITY. NAME has three columns: id (primary key), first, and last. SOCIAL_SECURITY has two: id (primary key), and ssn.



I want a single entity bean to represent first name, last name, and SSN. According to the above passage, I should be able to map firstName to NAME.first, lastName to NAME.last, and ssn to SOCIAL_SECURITY.ssn.



I'm using resin as my EJB server and I haven't figured out how to do this yet. Does anyone have any information on how this is handled? I noticed that resin actually modifies the deployment descriptor of the beans, adding an sql-table tag in the entity element, and an sql-column tag in the cmp-field element. Isn't container-appended deployment information supposed to be kept elsewhere so that the deployment descriptor remains portable across different vendors? Are they intentionally breaking portability to tie the application to their platform?



(I noticed another sneaky thing--they provide an AbstractEntityBean class that they encourage you to extend instead of javax.ejb.EntityBean...it implements empty stub methods for ejbActivate(), ejbPassivate(), etc. Using it once again ties your EJBs to their product...Sun should add javax.ejb.EntityBeanAdapter to their stuff.)



sev

   <<Less
About | Sitemap | Contact