Get Richard Monson-Haefel's book "Enterprise Java Beans". It explains things
pretty well.

The whole point of CMP is that you don't know (or aren't supposed to know or
care) how the EJB server stores your EJBs in the database. The folks who
wrote the EJB server are supposed to have studied O/R mapping issues, chosen
their approach, and implemented it. Then, they can compete on speed,
ease-of-use, GUI tools etc. Some vendors have even put in hooks to allow O/R
mapping tool makers to put their O/R mapping engines into their EJB server
to give you choices about which vendor does the CMP for you.

For now, you do care how this happens because the EJB server developers may
not have chosen the approach that best fits your project. Plus, you really
can't make a pure OO model with entity beans because the spec writers chose
not to deal with the issue of component inheritance (because it's hard and
contentious and some vendor's approach would lose, costing that vendor a lot
of money). By the way, PowerTier does do component inheritance, and it's
such a seductive feature that it almost guarantees vendor lock-in.

Each EJB is logically one class. To implement the class, you need a couple
interfaces and a class or two to describe your class since the EJB model
can't just take your one class and expose it's public methods and attributes
via RMI (which is how COM worked with Java and was a great idea -- too bad
it didn't make it into the real Java world). Plus, there's all those object
factory issues....

Inheritance aside, with CMP you create your component model (without
inheritance), do the right thing with the ejb-jar.xml file, package it all
up in a jar file and hand it to Orion (after getting all the various
configuration XML files right :-) and a database magically appears. It
really is that simple. But it can be hard to wrap your brain around if
you're used to writing SQL yourself.

If you have an existing data model that you must support, and you don't want
to use BMP, then you need to figure out how to "reverse engineer" it into an
orion-ejb-jar.xml file. However, you should understand that most EJB servers
use a "table-per-class" model for doing the persistence (something else that
hinders inheritance). Each component will be in its own table and no joins
are permitted other than those you can do implicitly by using attributes of
the various Collection classes in your bean. For example, having a List
object inside your bean results in a table being created to handle the
one-to-many relationship between your bean class and the class being stored
in the list. But the CMP engine manages all that for you. But, you are
limited to the data models that the CMP engine understands (table-per-class,
period).

The EJB 2.0 spec really improves the CMP side of things with its additions
to the ejb-jar.xml DTD that allow you to give better hints to the CMP engine
about how your classes are related and stored in the database. You should
get the draft EJB 2.0 spec (which I think comes with the Orion docs) and
read it. It's not as dry as it could be.

Kurt in Atlanta

>-----Original Message-----
>From: Kevin Duffey [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, September 12, 2000 11:18 AM
>To: Orion-Interest
>Subject: RE: OR mapping of table joins for CMP
>
>
>Hi,
>
>This is to Nick, and anyone else that can shed some light..
>
>> If you did this you would find that Orion would auto-create
>> tables that are
>> basically identical in form to those that you have, but probably with
>> different names.  If you now go into the orion-ejb.xml file 
>that orion
>> generates you can change the table and column names to those that you
>> already have. When you have done this, you have the two tables linked
>> transparently by Orion.  Just asking for a Person will automatically
>> retrieve the Job, and from that you can retrieve the job_description.
>
>I would like to learn HOW I can learn this. :) I know nothing 
>of CMP and O/R
>at this point, so where do I start learning? I can't just load 
>up Orion and
>blindly code this stuff..is there a good book on CMP and O/R 
>with EJBs? I
>realize each vendor has their own implementation of how CMP 
>works, but I
>would like to know more about it.
>
>One thing that caught my eye, from what you said, it sounds 
>like you don't
>create database tables from a special tool, then write SQL and 
>other stuff
>to insert, remove, update and search? Is this the case with 
>O/R and CMP? Do
>you define an entity bean class, and the app server 
>automatically generates
>a table for you in the database? If that is the case, how 
>exactly does it do
>this for any database type? I am using Interbase 6.0 at home, 
>and the SQL
>for Interbase (mainly the data types) is different than that 
>of Oracle. I do
>see the /config/datasource dir that maps various database data 
>types..so I
>am going to take a wild guess and assume Orion uses the 
>information in there
>for its mappings.
>
>Anyways, I would like to buy a book, or see some online 
>tutorials on how
>this all works, and how I can use it. Also, do modeling tools 
>(UML) work
>with CMP and O/R for you? Is it as easy as making some diagrams that
>describe the database table(s) and it writes the entity bean for you?
>
>Thanks.
>
>

Reply via email to