Terran,
Let me try to explain how we at Secant Technologies have implemented your
question below.  Keep in mind that the current EJB specification does not
define how relationships between Entity beans are to be represented and
persisted, so what I am explaining is how we deal with this in our
products(Enterprise Server for EJB - EES/EJB or Java Persistent Object
Service - JPOS).

With EES/EJB, a relationship between two objects is represented by a field
and corresponding setter and getter.  If the relationship is a 1..many, then
the type of the field is a Java collection with a getter method returning
the collection holding the related objects.  So in your example below,
Course would have a field of type Students together with a getter method
returning the collection of related Student objects.   But our view is that
you should not have to write the code which handles object relationships....
it should be provided by the persistence infrastructure and just happen for
you when you reference the relationship.

Here is how the process works ...
1. You define your object model, including the relationships( 1..1, 1 ..
many, many-to-many, etc.)  in UML.   As part of that definition you include
additional implementation details (e.g. specifying O/R mapping rules,  which
objects are to be Entity beans, Session beans, persistent sub-objects, etc.)

2. Using a tool we provide with our products, you generate skeleton Entity
bean implementation classes for all of the objects in the model which have
been specified to be Entity beans, and we create a meta-data file which
describes the object model.  You'll see in a minute, this meta-data file is
used at runtime by our EJB container.

The tool maps a relationship in the model to a Java field and a pair of
"getter and setter" methods.  If the relationship is 1..many or many..many,
the type of the field is a collection which is used to hold the related
objects when they are brought into memory.  The tool "writes" the body of
the "getter" method for you... you do not have to write the "getter or
setter" methods yourself.   Essentially, the tool generates code that calls
on the Persistent Object Service (POS) provided by the EES/EJB Container.

3. So, when you want to "getCoursesByStudent" , you restore the Student
object and then call the "getter" method corresponding to the field holding
the Courses.   This "getter" method uses the services of the POS(i.e.
Container) to restore the related Courses by using the meta-data file
mentioned earlier and constructing the appropriate query(s) to the
relational database to restore the Course objects. It builds the Java
collection and populates it with corresponding Course objects retrieved from
the database.  The getter method returns the collection and you can use
normal techniques in dealing with the collection.

Hope this helps..... at least it gives you some insight on how we deal with
your question.

Dave Tillman
Secant Technologies

----- Original Message -----
From: Terran Vigil <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 20, 1999 12:12 PM
Subject: finders for non-dependent entities


> Let's say you have to two entity beans representing a manay-to-many
> relationship in the database. In my case we have Courses and Students.
Where
> is the best place to implement a "get courses by student"?
>
> I could add a finder to Course - .findByStudent(). However, this doesn't
> seem like the clear choice since Student isn't a dependent entity of
Course.
> Would I be better off creating a Session bean that had a method
> .getCoursesByStudent and made the JDBC call directly?
>
> In the latter case, I could could just extract the data and not
instantiate
> any Entity Beans - this seems to be the trend.
>
> Any comments?
>
>
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to