If you get the Java 2 Enterprise Edition Developers Guide (I have v
1.2.1 pdf) from www.java.sun.com 
Then it is on page 135 - Mapping Table Relationships to Entity beans
It goes on to describe when you should use entity beans, and when to use
helper classes (hint: that is what you need!)
It also gives a good example with source code.
Be warned though; you will have to use BMP!


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] On Behalf Of Maximilian
Eberl
Sent: 24 April 2002 13:13
To: Orion-Interest
Subject: OffTopic: Entity-Beans and relational structure

Excuse me for asking off topic (and stupid), I am just learning to use
Entity Beans on Orion.

In most tutorials entity beans only represent ONE ROW from ONE TABLE,
but
relational databases go far beyond that.

I have a relational database for movies, actors, directors & writers.

So I have a table tblMovies
INT id, VARCHAR title, INT year, VARCHAR description
e.g.:
1, 'Casablanca',1942,'the classical movie'
2, 'The Maltese Falcon',1946,'begin of the dark series'
3, 'The Seawulf',1947,'after the novel from Jack London'
...

I have a tblActors (INT id, VARCHAR name)
1,'Humphrey Bogart'
2,'Ingrid Bergman'
3,'Edward G. Robinson'
...

and in the same manner tblDirectors, tblWriters

And I have tables for the relations, e.g.

tblRoles (INT filmid, INT actorid)
1,1
2,1
1,2
3,3
..
and also tblMisEnScene, tblScreenplay

meaning: Humphrey Bogart (actorid: 1) appeared in 'Casablanca' (filmid:
1)
and 'The Maltese Falcon' (filmid: 2), Ingrid Bergman (actorid: 2)
appeared
in 'Casablanca' (filmid: 1), Edward G. Robinson (actorid: 3) appeared in
'The Seawulf' (filmid: 3) . So this relational structure allows that one
film can have multiple actors, writers, directors and one actor can
appear
in multiple films. Relational basework, of course.

If I want to extract those films in which Humphrey Bogart appeared I can
do
this easily in SQL (used by a Servlet) with:

SELECT title FROM tblFilms WHERE id IN (SELECT filmid FROM tblRoles
WHERE
actorid=(SELECT id FROM tblActors WHERE name='Humphrey Bogart'))

(or as in my case with JOINS from MySQL)

When I do want to write an EJB-Application using this database, how do I
do
this ? How do I represent the relational data ?

Do I have to keep Entity Beans for EVERY row of ANY table ? Do I have to
create temporary tables with all information merged ? This creates a
problem
because one film can have one or more writers (Casablanca had three) and
(in
most cases) more than one actor.

This way  ?

public class MovieBean implements javax.ejb.EntityBean
    {
    String Title;
    String[] Actors;
    ...
    public String getTitle() throws RemoteException;
        {...
        }
    public String[] getActors() throws RemoteException;
        {
        return Actors[];
        }
    }

using Arrays filled from the database with all actors, directors,
writers ?

Please give me a hint ! (Well, I know I am stupid. But it is a good work
to
help stupid persons)


Maximilian Eberl
http://www.derdickemax.de
mailto:[EMAIL PROTECTED]





Reply via email to