You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Rodolfo García Esteban/CYII <rg...@cyii.es> on 2006/01/25 13:56:09 UTC
relationship m:n
Hi all,
I have an relationship m:n in my object model, this is implemented by a
relationship table. And I'm thinking what would be the correct way to
implement inserts and updates in this relationship table.
I would appreciatte all opinios.
Thanks
Rodolfo
________________________
RE: relationship m:n
Posted by Meindert <me...@pastelebusiness.com>.
I would:
Assume you have m:n relation between classroom and students;
You would probably have a classroom object containing a list with students
(And a student object containing a list of classrooms)
When persisting the classroom I would (in a transaction)
update the classroom (or insert when classroom_ID==null)
walk through the list of Students and insert the new students (when
student_ID==null)
(retrieve the generated ID of the new Students)
remove all (old) related Students out of the relationship table
insert all the related student_IDs from the list
Dont know if its right, but it works fine for me :-)
Also tried a way so I didnt have to delete and insert the same record;
- Add a deleteMe flag to the relationtable
When doing the persisting set all the deleteMe sto true for the current
classroom
Walk through the list of students and update the flag to false of the
relation table
If no rows where updated insert a row
Delete all rows where deleteMe is true
MEINDERT HOVING
_____
From: Rodolfo García Esteban/CYII [mailto:rgarciaesteban@cyii.es]
Sent: 25 January 2006 02:56 PM
To: user-java@ibatis.apache.org
Subject: relationship m:n
Hi all,
I have an relationship m:n in my object model, this is implemented by a
relationship table. And I'm thinking what would be the correct way to
implement inserts and updates in this relationship table.
I would appreciatte all opinios.
Thanks
Rodolfo
________________________
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.14.22/239 - Release Date: 24/01/2006
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.14.22/239 - Release Date: 24/01/2006