Hi all,
Is it possible to have a client (a session bean) handling this kind of relationship transparently when an attribute is associated to the relation?
Here is a comprehensive description of the issue:
Data Model
----------
-------------------
¦ STUDENT ¦
¦ - student_id (pk) ¦
¦ - name ¦
¦ ¦
-------------------
¦1
¦
¦
¦
¦n
-------------------
¦ GRADE ¦
¦ - course_id (fk) ¦
¦ - student_id (fk) ¦
¦ - grade (integer) ¦ <-- this is the issue
-------------------
¦n
¦
¦
¦
¦1
------------------
¦ COURSE ¦
¦ - course_id (pk) ¦
¦ - code ¦
¦ ¦
------------------
Is it possible to map this to a N-M relationship between a Student class and a Course class?
The answer is usually yes, but this time the "grade" attribute causes me a lot of trouble.
Is it possible to do something like:
student.getCourses().add(course,8)
with 8 being the grade for this course and this student?
The idea is that a call to the add() method would trigger an insert of a new row in the 'GRADE' table. getCourses() could return a Map, with a Course as key and an Integer (the grade) as value.
If, as it seems, this is not possible in a simple declarative way, we would then fully promote GRADE as a plain EJB, and have two 1-N relationships, but I would like to hide the 'Grade' entity inside the Java code.
Thanks for your help,
Chris.
-
many-to-many relationship with an attribute on the relation (1 messages)
- Posted by: Christophe Alexandre
- Posted on: August 04 2003 08:43 EDT
Threaded Messages (1)
- many-to-many relationship with an attribute on the relation by Ian Mitchell on August 04 2003 17:08 EDT
-
many-to-many relationship with an attribute on the relation[ Go to top ]
- Posted by: Ian Mitchell
- Posted on: August 04 2003 17:08 EDT
- in response to Christophe Alexandre
I'd prefer to keep the Course and Student entities grade agnostic, and introduce a GradeController SLSB that manipulates the Grade table directly. What I'm wary of is introducing "simple" relationship accessors into an entity that:
- would then share responsibility for the CRUD of the grade with another entity in the association
- might easily develop its own business rules (e.g. notification if a grade is changed)