Hi,

Can anybody help me? I'm writing J2EE application above a legacy system and
I
have faced some problems. Suppose, there are 3 tables in my database that
look something like

-----------------
| Student |
|---------------|
| studentid |
| name |
-----------------
    | one
    |
    | many
----------------------
| Mark |
|--------------------|
| studentid |
| courseid |
| mark |
----------------------
    | many
    |
    | one
-----------------
| Course |
|---------------|
| courseid |
| name |
-----------------

It's easy to see that Student and Course beans are similar, so it's enough to consider only two beans of all, say Student and Mark.

1. What is the *right* way to map this tables to BMP EJB?
Should the Student keep list of courseIds as follows

    private ArrayList courseIds; // list of courses related to student
    private MarkHome markHome; // Home for Mark

or keep list of Marks and obtain related Courses by using this list
    private ArrayList marks; // list of marks related to student

or keep only markHome and every time dynamically obtain related Marks and Courses by findByXXX methods when needed
    private MarkHome markHome; // Home for Mark

How should the Mark bean look?

2. Concurrency problem. For instance, consider the second option above. State of Student is synchronized with database by ejbLoad() and ejbStore().But EJB Container doesn't know that somebody else modifies the tables apart
as the legacy system still goes on working. Therefore, on my mind, a situations can appear when the container and a direct (thick) client will mess up each other.
The order of events could be following:

1. student.ejbLoad()
2. Thick client updates student
3. container decides to Passivate student
    student.ejbStore() ---------- this overwrites previous record's changes instead of synchronization the bean's state to database
    student.ejbPassivate()

What is wrong?